SupabaseS
Supabase•12mo ago
Fares

Cookie set then suddenly removed when deployed

My deployed nextjs app has a strange behavior that doesn't occur in localhost (as you can see in the video)
When authenticated via Supabase, the cookie is set, then suddenly removed.
I tried debugging this, in the middleware, server & client.
I've tried configuring the cookie options manually so I'd be able to handle multiple envs (local vs preview vs prod):
export const COOKIE_OPTIONS: CookieOptionsWithName = {
    domain: process.env.NODE_ENV === 'development' ? '.localhost' : `.aaql.fr`,
    path: '/',
    expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30),
    httpOnly: true,
    secure: process.env.NODE_ENV === 'production',
    sameSite: 'lax',
}

You'll find the code for the server.ts, client.ts & middleware.ts in the following gist: https://gist.github.com/FaresKi/2bf082eacce888431d7f28c640e8b0c4.

Is there something i can do in the meantime to debug ? As it's a pain to troubleshoot haha 😅
Was this page helpful?