Skip to content
Back

session.secret is empty when using node-appwrite in Next.js Server Action

  • 0
  • Auth
QLiêm
27 Feb, 2026, 15:17

I am implementing SSR authentication using Next.js Server Actions and node-appwrite. The session is created successfully, but session.secret is empty. Here is my server-side login code: "use server"; import { Client, Account } from "node-appwrite"; import { cookies } from "next/headers";

export const signInUser = async ({ email, password }) => { try { const client = new Client() .setEndpoint(process.env.APPWRITE_ENDPOINT) .setProject(process.env.APPWRITE_PROJECT_ID);

TypeScript
const account = new Account(client);

const session = await account.createEmailPasswordSession(email, password);

console.log(session);

if (!session.secret) {
  console.log("Secret Empty");
}

const cookieStore = await cookies();
cookieStore.set("appwrite-session", session.secret, {
  path: "/",
  httpOnly: true,
  sameSite: "strict",
  secure: true,
});

return { success: true, sessionId: session.$id };

} catch (error) { console.error("Appwrite Login Error:", error); } };

TL;DR
Issue: session.secret is empty when using node-appwrite in Next.js Server Action. Solution: The session is created successfully, but the session.secret is empty. This may be because the cookies are not being properly stored. Ensure that the cookieStore is correctly instantiated before setting the cookie. It's important to handle possible errors that may occur during the cookie setting process.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more