Skip to content

Commit

Permalink
feat: 토큰 만료일 확인 함수 구현
Browse files Browse the repository at this point in the history
쿠키에 저장된 만료일과 현재 시각을 비교하여 만료일이 지나면 토큰이 자동으로 삭제되도록 구현했습니다.
  • Loading branch information
JeonDoGyun committed Oct 30, 2023
1 parent c5fd67f commit 5a63b40
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/commons/cookie/getUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ export const getLoginState = () => {
return '로그인';
};

export const validateExpiredToken = () => {
const now = new Date();
const expiredDate = new Date(getCookie('expiredDate'));
console.log('만료 검사');

// 토큰만료 검사 후 삭제
if (now > expiredDate) {
removeCookie('loginToken');
removeCookie('expiredDate');
removeCookie('userAccountInfo');
console.log('토큰이 만료되어 삭제되었습니다.');
}
};

export const removeToken = () => {
removeCookie('loginToken');
};

0 comments on commit 5a63b40

Please sign in to comment.