Rank 2: Process
Next.js:
-
After logging in, we get a cookie with the appwrite session name, as expected. This is detected here, since we get a cookie matching the session name.
-
We are able to get the { account } and I have logged that session was found. See code snippet below.
-
The AppwriteException is thrown at
await account.deleteSession("current"). Even though we have fetched an account, we have a seession, and that is the same session that is created during login. See login snippet below as well. -
What the fudge is this behavior? Is this not the correct way to delete a session server side?
"use server";
import { createSessionClient } from "@/adapters/infrastructure/appwrite/server/appwrite-server-config";import { cookies } from "next/headers";import env from "@/config/env";
export const logoutAction = async () => { const sessionCookie = cookies().get(env.appwriteSessionName); if (!sessionCookie) { return { error: "Ingen session funnet", }; }
try { const { account } = await createSessionClient(sessionCookie); await account.deleteSession("current"); cookies().delete(env.appwriteSessionName); return { success: true, }; } catch (error) { console.error("Logout Error: ", error); return { error: "Noe gikk galt, kunne ikke logge deg ut", }; }};This is how we create the client session client, which confirms we found a session that we set:
export const createSessionClient = async (session: any) => { const client = new Client() .setEndpoint(env.publicAppwriteEndpoint) .setProject(env.publicAppwriteProject);
if (session) { console.log("Session Found!") client.setSession(session); } else { console.log("Session NOT Found: Could not set it!") }
return { get account() { return new Account(client); }, get users() { return new Users(client); }, get databases() { return new Databases(client); }, };};