Next.js Discord

Discord Forum

Why I am not able to get the cookies in route handlers? (App Dir)

Unanswered
sourab posted this in #help-forum
Open in Discord
Here's the config of the cookie I am setting when user logs in
   cookies().set(AUTH_COOKIE, encryptedToken, {
      secure: process.env.NODE_ENV !== 'development',
      httpOnly: true,
      path: '/',
      maxAge: 7 * 24 * 3600000,
      sameSite: 'lax',
    });

This encryptedToken contains refresh token to rotate user's token when needed.

In my refresh token route handler file I am trying to access the AUTH_COOKIE but getting null. Any idea why?

 const sessionToken = cookies().get(AUTH_COOKIE)?.value

1 Reply

@joulev @Western harvester ant can you guys take look? Please