Skip to content

Commit

Permalink
Merge pull request #43 from DevKor-github/develop
Browse files Browse the repository at this point in the history
feat(auth): set tokens' expires
  • Loading branch information
astorverse authored Jul 23, 2024
2 parents 0fca11f + 5ae6619 commit 9b1ee23
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/APIs/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,24 @@ export class AuthController {

// 클라이언트 도메인 설정
const clientDomain = process.env.CLIENT_DOMAIN;
const oneDay = 24 * 60 * 60 * 1000; // 하루(밀리초)
const accessExpiryDate = new Date(Date.now() + oneDay);
const refreshExpiryDate = new Date(Date.now() + oneDay * 30);

res.cookie('accessToken', accessToken, {
httpOnly: true,
domain: clientDomain,
sameSite: 'none',
secure: true,
expires: accessExpiryDate,
});
res.cookie('refreshToken', refreshToken, {
httpOnly: true,
domain: clientDomain,
sameSite: 'none',
secure: true,
expires: refreshExpiryDate,
});
res.cookie('isLoggedIn', true, { httpOnly: false, domain: clientDomain });

return res.redirect(process.env.CLIENT_URL);
// return res.send();
Expand All @@ -83,12 +87,15 @@ export class AuthController {
req.cookies.refreshToken,
);
const clientDomain = process.env.CLIENT_DOMAIN;
const oneDay = 24 * 60 * 60 * 1000; // 하루(밀리초)
const accessExpiryDate = new Date(Date.now() + oneDay);

res.cookie('accessToken', newAccessToken, {
httpOnly: true,
domain: clientDomain,
sameSite: 'none',
secure: true,
expires: accessExpiryDate,
});
return res.send();
} catch (e) {
Expand All @@ -106,7 +113,6 @@ export class AuthController {
sameSite: 'none',
secure: true,
});
res.clearCookie('isLoggedIn', { httpOnly: false, domain: clientDomain });

throw new UnauthorizedException(e.message);
}
Expand Down

0 comments on commit 9b1ee23

Please sign in to comment.