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
- Selfhost - Starting Docker containers fa...
I am stuck at installing appwrite. Specifically, the containers dont want to start up. The images are downloaded and ready. Dockhand is reporting containers st...
- It says domain already used but I have d...
I accidentally deleted the project in which I used my domain originally (orexia.app) from name.com. Now I am trying to add it to a different project and it says...
- Is this normal in the self host custom d...
when i try to add custom domain to the project did not see this in 1.8.0 ok when pressed the retry it says "DNS verification failed with resolver 8.8.8.8. Domai...