Skip to content

Commit

Permalink
feat: 로그인 api then/catch 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
guridaek committed Oct 8, 2023
1 parent 62d13f0 commit e79aebb
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions frontend/src/pages/GithubCallbackPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import React, { useContext, useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { ToastContext } from '@/contexts/ToastContext';
import { TOAST_ERROR_MESSAGE } from '@/constants/message';
import { useLogin } from '@/hooks/useLogin';
import LoadingPage from './LoadingPage';
import { issueLoginToken } from '@/apis/auth';

function GithubCallbackPage() {
const location = useLocation();

const { showErrorToast } = useContext(ToastContext);

const { goToMainPage, goToLoginPage } = usePageRouter();
const { login } = useLogin();

useEffect(() => {
const searchParams = new URLSearchParams(location.search);
Expand All @@ -26,9 +25,15 @@ function GithubCallbackPage() {
}

if (code) {
login(code).then(() => {
goToMainPage();
});
issueLoginToken(code)
.then(() => {
goToMainPage();
})
.catch(() => {
showErrorToast(TOAST_ERROR_MESSAGE.LOGIN);

goToLoginPage();
});
}
}, [location]);

Expand Down

0 comments on commit e79aebb

Please sign in to comment.