This Set-Cookie was blocked because it had the "Secure" attribute but was not received over a secure connection. when setting a path

Viewed 677

I am trying to store a token in the cookies when an endpoint /auth/user/login is called, the access_token gets store correctly, but chrome says in the network tab for the refresh_token that This Set-Cookie was blocked because it had the "Secure" attribute but was not received over a secure connection.

I am working in development mode.

The only difference is that I have set a path in the cookie config. If I remove that path, then it works correctly.

router.post(
  '/auth/user/login',
  handleErrorAsync(async (req: Request, resp: Response) => {
    const { username, password } = req.body;
    const response = await getUserToken(username, password);

    resp.cookie('access_token', response.access_token, {
      httpOnly: true,
      secure: process.env.NODE_ENV === 'production',
      expires: new Date(response.expires_at),
    });
    resp.cookie('refresh_token', response.refresh_token, {
      httpOnly: true,
      secure: process.env.NODE_ENV === 'production',
      expires: new Date(Date.now() + FIVE_MONTHS),
      path: '/api/auth/user/refresh'
    });
    resp.json(response);
  })
);
0 Answers
Related