cookies icon indicating copy to clipboard operation
cookies copied to clipboard

Cookie overwrite not working

Open pullmann4rent opened this issue 1 year ago • 1 comments

Hello,

I want to overwrite my cookie but my maxage expiration are set to "session". By default I set an maxage to 30 days but when I overwrite the cookie it set to "session".

export const refresh = async (req: Request, res: Response) => {
  try {
    const cookies = new Cookies(req, res, { keys: cookieKeys });

    const result = await supabase.auth.refreshSession({refresh_token: req.body.refresh_token});
    const data = result.data;
  
    if(!data.user || !data.session) {
      Sentry.captureException(result.error);
      throw new ErrorException(500, 'Es ist ein Fehler aufgetreten.');
    }

    const userInfo = {
      user: {
        id: data.user.id,
        email: data.user.email,
        app_metadata: data.user.app_metadata,
        user_metadata: data.user.user_metadata,
      },
      session: {
        access_token: data.session.access_token,
        expires_in: data.session.expires_in,
        expires_at: data.session.expires_at,
        refresh_token: data.session.refresh_token
      }
    };

    cookies.set('user', JSON.stringify(userInfo.user), { overwrite: true, httpOnly: false });
    cookies.set('jwt' , JSON.stringify(userInfo.session), { overwrite: true, httpOnly: false });
    res.status(200).json(userInfo);

€: I have a nodejs backend running on port :3000 and react frontend running it on port: 5173 both are localhost

pullmann4rent avatar May 26 '24 14:05 pullmann4rent

Explicitly Set maxAge When Overwriting Cookies Handle Cross-Origin Requests Properly ensure that the SameSite attribute of the cookies is set appropriately (e.g lax or none), and if SameSite=None is used, the Secure flag must also be set.

Verify Cookie Configuration at last..

crocodilelurker avatar May 16 '25 13:05 crocodilelurker