Skip to content
Back

Login server-side action (NextJS) not creating session cookie

  • 0
  • Auth
  • Web
  • Cloud
Ryan Baig
30 May, 2025, 06:25

(for @Kenny) hello, so I created this login function:

TypeScript
export async function logIn(email: string, password: string) {
  const account = new Account(client);

  try {
    const session = await account.createEmailPasswordSession(email, password);
    console.log("Login successful:", session);
    (await cookies()).set(COOKIE_KEY, session.secret, {
      path: "/",
      httpOnly: true,
      sameSite: "strict",
      secure: true,
    });

    return session;
  } catch (error) {
    console.error("Login failed:", error);
    throw error;
  }
}

problem is, session is created successfully, but the cookie is not being created (ss of application tab of devtools sent)

TL;DR
Developers having issues creating a session cookie while logging in using NextJS. The problem is that the cookie is empty because the secret isn't provided on the client-side session creation. Secret should not be exposed on the client-side. The code snippet provided calls for the cookie to be set with the session secret, but it's not working. Ensure that secrets are handled properly and not exposed.
Ryan Baig
30 May, 2025, 06:26

huh???

Ryan Baig
30 May, 2025, 06:26

Windows 95 😭

Ryan Baig
30 May, 2025, 06:29

nevermind, I know whyy. secret isnt given on client side session creation.

Ryan Baig
30 May, 2025, 06:32

now I am going try what happens if I uninstalled appwrite and used node-appwrite

Ryan Baig
30 May, 2025, 06:33

still same result.

Ryan Baig
30 May, 2025, 06:33

it created an empty cookie

Ryan Baig
30 May, 2025, 06:41

@Kenny how do I get the session key 😭

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