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 b39ad83 commit a29dcb9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/pages/auth/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { Form, FormControl, FormField, FormItem, FormMessage } from '@/components/ui/form';
import { PostSigninRequest, PostSigninRequestType } from '@/schema/auth';
import useSigninMutation from '@/hooks/useSignInMutation';
import useRefreshToken from '@/hooks/useRefreshToken';

export default function SignIn() {
const mutationSignin = useSigninMutation();
const { mutate: refreshAccessToken } = useRefreshToken();
const router = useRouter();

useEffect(() => {
const accessToken = localStorage.getItem('accessToken');
if (accessToken) {
const refreshToken = typeof window !== 'undefined' ? localStorage.getItem('refreshToken') : null;

if (refreshToken) {
refreshAccessToken({ refreshToken });
router.push('/epigrams');
}
}, [router]);
}, [refreshAccessToken]);

// 폼 정의
const form = useForm<PostSigninRequestType>({
Expand Down
10 changes: 7 additions & 3 deletions src/pages/auth/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
import useRegisterMutation from '@/hooks/useRegisterMutation';
import useRefreshToken from '@/hooks/useRefreshToken';

export default function SignUp() {
const [focusedField, setFocusedField] = useState<string | null>(null);
const { mutate: refreshAccessToken } = useRefreshToken();
const router = useRouter();

useEffect(() => {
const accessToken = localStorage.getItem('accessToken');
if (accessToken) {
const refreshToken = typeof window !== 'undefined' ? localStorage.getItem('refreshToken') : null;

if (refreshToken) {
refreshAccessToken({ refreshToken });
router.push('/epigrams');
}
}, [router]);
}, [refreshAccessToken]);

const form = useForm<PostSignUpRequestType>({
resolver: zodResolver(PostSignUpRequest),
Expand Down

0 comments on commit a29dcb9

Please sign in to comment.