try {
                  
                  
                              const { errors, input } = await RequestValidator(LoginRequest, req.body);
                  
                  
                              if (errors) {
                  
                  
                                  throw new AuthFailureError(errors as string);
                  
                  
                              }
                  
                  
                  
                  
                  
                              const response = await this.authService.login(input);
                  
                  
                              const cookies = req.cookies;
                  
                  
                              if (cookies && cookies[config.TOKEN_INFO.refreshTokenName]) {
                  
                  
                                  const tokenExsists = await this.tokenService.checkRefreshToken(cookies[config.TOKEN_INFO.refreshTokenName], response.user.id as string);
                  
                  
                                  if (tokenExsists) {
                  
                  
                                      await this.tokenService.deleteToken(cookies[config.TOKEN_INFO.refreshTokenName], response.user.id as string);
                  
                  
                                  }
                  
                  
                                  res.clearCookie(
                  
                  
                                      config.TOKEN_INFO.refreshTokenName,
                  
                  
                                      clearRefreshTokenCookieConfig
                  
                  
                                  );
                  
                  
                              }
                  
                  
                  
                  
                  
                              const accessToken = await this.tokenService.generateAccessToken({ userId: response.user.id as string });
                  
                  
                              const refreshToken = await this.tokenService.generateRefreshToken({ userId: response.user.id as string });
                  
                  
                              await this.tokenService.saveToken(refreshToken, response.user.id as string);
                  
                  
                  
                  
                  
                              // res.cookie(
                  
                  
                              //     config.TOKEN_INFO.refreshTokenName,
                  
                  
                              //     refreshToken,
                  
                  
                              //     refreshTokenCookieConfig
                  
                  
                              // )
                  
                  
                  
                  
                  
                  
                  
                  
                              res.setHeader('Set-Cookie', refreshToken=${refreshToken}; HttpOnly; Path=/; Max-Age=${config.TOKEN_INFO.refreshTokenValidityDays}; SameSite=None; Secure; Partitioned);
                  
                  
                              const result = {
                  
                  
                                  userId: response.user.id,
                  
                  
                                  accessToken
                  
                  
                              }
                  
                  
                              new SuccessResponse('User logged in successfully', { ...result }).send(res);
                  
                  
                          } catch (error) {
                  
                  
                              next(error);
                  
                  
                          }
                  
                  
                      }
                  
                  
                  
                  
                  
                  
                  
                  
                  any one know why this is not setting the cookies in the nextjs frontend? it is working fine in postman
                  
                  
                
1. add tree ` in start and end of code to format it like code. it will be like this const div = document.createElement("div");
Обсуждают сегодня