Skip to content

Commit

Permalink
feat/#39/jwt 쿠키 access와 refresh로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
gwgw123 committed Dec 6, 2024
1 parent d0f40d3 commit 25f9274
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,43 @@ export class AuthController {
@Get('google/callback')
@UseGuards(AuthGuard('google'))
async googleLogin(@User() user: any, @Res() res: Response) {
const jwtToken = await this.authService.googleLogin(user);
console.log(jwtToken);
const { accessToken, refreshToken } =
await this.authService.googleLogin(user);

// 쿠키와 리다이렉트의 설정은 클라이언트가 원하는 곳으로 지정해준다.
// res.cookie 의 domain부분과 res.redirect의 url부분의 도메인을 일치시켜야 한다.
res.cookie('jwt', jwtToken, {
const cookieOptions = {
httpOnly: true,
secure: true,
domain: this.configService.get<string>('COOKIE_DOMAIN'),
sameSite: 'none',
sameSite: 'none' as 'none', // none 타입으로 지정해줘야 함.
maxAge: this.configService.get<number>('COOKIE_EXPIRATION'),
});
};

const cookies = [
{
name: 'accessToken',
value: accessToken,
options: { ...cookieOptions },
},
{
name: 'refreshToken',
value: refreshToken,
options: { ...cookieOptions },
},
];

for (const cookie of cookies) {
res.cookie(cookie.name, cookie.value, cookie.options);
}

// res.cookie('accessToken', accessToken, {
// httpOnly: true,
// secure: true,
// domain: this.configService.get<string>('COOKIE_DOMAIN'),
// sameSite: 'none',
// maxAge: this.configService.get<number>('COOKIE_EXPIRATION'),
// });

res.redirect(this.configService.get<string>('CLIENT_MAIN_PAGE_URL'));
}
Expand Down

0 comments on commit 25f9274

Please sign in to comment.