Skip to content

Commit

Permalink
feat: 15분마다 토큰 인증 post 요청하는 커스텀 훅 작성 #179
Browse files Browse the repository at this point in the history
  • Loading branch information
seoye0ng committed Feb 20, 2024
1 parent 489aeae commit 05dec8e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/hooks/useIntervalRefreshToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import useRefreshToken from '@remote/queries/auth/useRefreshToken';

const JWT_EXPIRY_TIME = 15 * 60 * 1000;

function useIntervalRefreshToken() {
const { mutate: refresh } = useRefreshToken();
let refreshTokenInterval: NodeJS.Timeout;

const startRefreshTokenInterval = () => {
refreshTokenInterval = setInterval(() => {
refresh();
}, JWT_EXPIRY_TIME);
};

const refreshTokenClear = () => {
clearInterval(refreshTokenInterval);
};

return { startRefreshTokenInterval, refreshTokenClear };
}

export default useIntervalRefreshToken;

0 comments on commit 05dec8e

Please sign in to comment.