Skip to content

Commit

Permalink
feat: 로그인 로직 변경에 따른 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeml06 committed Oct 22, 2024
1 parent 5cfecc4 commit 9f4d72a
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions frontend/src/pages/Login/OAuthLoginPage/OAuthLoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import ROUTES from '@_constants/routes';
import { getInviteCode } from '@_common/inviteCodeManager';
import { kakaoOAuth, googleOAuth } from '@_apis/auth';
import { googleOAuth } from '@_apis/auth';
import { setAccessToken } from '@_utils/tokenManager';
import { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { ApiError } from '@_utils/customError/ApiError';
import useMigrationOAuth from '@_hooks/mutaions/useMigrationOAuth';
import GET_ROUTES from '@_common/getRoutes';

type Provider = 'apple' | 'google' | 'kakao';

export default function OAuthLoginPage() {
const navigate = useNavigate();
const params = useParams<'provider'>();
const provider = params.provider as Provider | undefined;
const { mutate: kakaoMigration } = useMigrationOAuth(
() => navigate(`${GET_ROUTES.default.resultMigration}/sucess`),
() => navigate(`${GET_ROUTES.default.resultMigration}/fail`),
);

useEffect(() => {
const loginOAuth = async () => {
Expand Down Expand Up @@ -39,30 +44,20 @@ export default function OAuthLoginPage() {
apple: async () => {
setAccessToken(codeOrToken);
navigate(ROUTES.kakaoSelection);
return true; // 조기 반환
},
google: async () => {
const response = await googleOAuth(codeOrToken);
setAccessToken(response.data.accessToken);
navigate(ROUTES.kakaoSelection);
return true; // 조기 반환
},
kakao: async () => {
await kakaoOAuth(codeOrToken);
kakaoMigration(codeOrToken);
},
};

const handler = oauthHandlers[provider];

const shouldReturn = await handler();
if (shouldReturn) return;

const inviteCode = getInviteCode();
if (inviteCode) {
navigate(`${ROUTES.darakbangInvitationRoute}?code=${inviteCode}`);
} else {
navigate(ROUTES.darakbangSelectOption);
}
await handler();
} catch (error) {
if (error instanceof ApiError) {
alert(error.message);
Expand Down

0 comments on commit 9f4d72a

Please sign in to comment.