Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie overwrite not working #155

Open
pullmann4rent opened this issue May 26, 2024 · 0 comments
Open

Cookie overwrite not working #155

pullmann4rent opened this issue May 26, 2024 · 0 comments

Comments

@pullmann4rent
Copy link

pullmann4rent commented May 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants