Skip to content

Commit

Permalink
✨ 리프레시 토큰 훅 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jangmoonwon committed Aug 6, 2024
1 parent 919ab42 commit b39ad83
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/hooks/useRefreshToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useMutation } from '@tanstack/react-query';
import { postRefreshToken } from '@/apis/auth';
import { PostRefreshTokenRequestType, PostRefreshTokenResponseType } from '@/schema/auth';

const useRefreshToken = () =>
useMutation<PostRefreshTokenResponseType, Error, PostRefreshTokenRequestType>({
mutationFn: postRefreshToken,
onSuccess: (data) => {
localStorage.setItem('accessToken', data.accessToken);
},
onError: () => {
localStorage.removeItem('refreshToken');
},
});

export default useRefreshToken;

0 comments on commit b39ad83

Please sign in to comment.