Cookie setting in hapi js but it is not storing in browser

46 views Asked by At

I'm trying to setup the cookie in request headers in the following way.

server.route({
    method: 'POST',
    path: '/login',
    options: {
      validate: {
        payload: Joi.object({
          username: Joi.string().required(),
          password: Joi.string().required()
        })
      }
    },
    handler: (request, h) => {
      // Generate a new access token
      const accessToken = generateAccessToken(username);
  
      // Generate a new refresh token
      const refreshToken = generateRefreshToken(username);
  
  
      const response = h.response({accessToken,refreshToken});
      const refreshTokenOptions = {
        ttl: 60 * 60 * 24,
        encoding: 'none',
        isSecure: false,
        isHttpOnly: false,
        path: '/',
        // domain: '.abc.com',
        strictHeader: true,
      };
      response.state('refreshToken', refreshToken, refreshTokenOptions);
      return response
    }
  });

and I'm consuming this API and getting success response but the cookie is not stored in the browser. The same API I tried in postman is successfully setting up the cookie in the postman cookie.

Am I doing anything wrong? Is a better approach to storing cookies(refreshToken).

0

There are 0 answers