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
- Cannot use custom SMTP for messaging (SM...
Hey there! I'm on Appwrite Self-hosted 1.9.0. I've never used the messaging feature before, always sent emails through functions or a custom backend, but I'v...
- CORS errors in Obsidian custom plugin
Hi, anyone here familiar with obsidian community plugins? In short: it's a local first note app which supports writing your own add-ons / plugin But I keep get...
- > AppwriteException: The requested servi...
When trying to read or write from my database I get the following error: > AppwriteException: The requested service is disabled. You can enable the service from...