I have the following server action that I am calling in order to login
export async function loginUser(prevState, formData) {
try {
const account = await createAdminClient();
const session = await account.createEmailPasswordSession(formData.get("email"), formData.get("password"));
cookies().set('session', session.secret, {
httpOnly: true,
secure: false,
sameSite: "strict",
maxAge: new Date(session.expire),
path: "/"
});
} catch(error) {
return {
message: error.message
}
}
revalidatePath('/auth/login');
redirect('/dashboard');
}
I also have the following function that I need to implement to logout, however, I need to first get the account to delete the session. I am using the next/headers
to grab cookies, and then retrieve the session object from there. That part works as expected. However, when I try to call acc.get()
I get general_unauthorized_scope
as the error, could someone take a look and tell me what I could be doing wrong?
export async function logoutUser(prevState, formData) {
try {
const session = cookies().get("session");
if (session) {
const acc = await getAccountFromSession(session);
acc.get().then(function (response) {
console.log(response)
})
}
} catch(error) {
console.log(error)
return {
message: error.message
}
}
}
getAccountFromSession(session)
btw
const getAccountFromSession = async (session) => {
const client = new Client()
.setEndpoint(process.env.REACT_APP_APPWRITE_BASE_URL)
.setProject(process.env.REACT_APP_APPWRITE_PROJECT_KEY)
.setSelfSigned(true) // TODO - Set this to false once deployed with an actual ssl certificate
if (session) {
client.setSession(session.secret)
}
return new Account(client);
}
Recommended threads
- Custom emails
What happen if I use a third party email provider to customize my emails and my plan run out of emails/month? Appwrite emails are used as fallback sending emai...
- Realtime with multiple connections
I need the Realtime on multiple Collections for diffrent applicational logic. So my question is: Is there a way to have only 1 Websocket connection or do I need...
- Can't login or deploy functions in Appwr...
Hello, since i updatet to the appwrite cli 6.1.0 i can't login or deploy functions with the cli. When i call the command: "appwrite get account --verbose" i ge...