Skip to content

Commit 0037b24

Browse files
committed
fix: qa
1 parent a0519eb commit 0037b24

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

apps/ticket/src/app/(pages)/auth/page.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { useLoginMutation } from "@/data/users/postUserLogin/mutation";
77
import { safeLocalStorage } from "@/lib/storage";
88
import { LoadingWithLayout } from "@/shared/components/LoadingWithLayout";
99
import { PATH } from "@/shared/constants/path";
10-
import { IS_LOGINED, SOCIAL_LOGIN_TYPE_KEY, TOKEN_KEY } from "@/shared/constants/storage";
10+
import {
11+
IS_LOGINED,
12+
REDIRECT_URL_KEY,
13+
SOCIAL_LOGIN_TYPE_KEY,
14+
TOKEN_KEY,
15+
} from "@/shared/constants/storage";
1116
import { REDIRECT_URI } from "@/shared/hooks/useOAuth/constants";
1217
import { SocialLoginType } from "@/shared/hooks/useOAuth/types";
1318

@@ -27,6 +32,7 @@ const AuthPage = () => {
2732
const authorizationCode = searchParams.get("code");
2833

2934
const socialType = safeLocalStorage.get(SOCIAL_LOGIN_TYPE_KEY) as SocialLoginType;
35+
const redirectUrl = safeLocalStorage.get(REDIRECT_URL_KEY);
3036

3137
const { mutateAsync } = useLoginMutation();
3238

@@ -40,8 +46,8 @@ const AuthPage = () => {
4046
});
4147
safeLocalStorage.set(IS_LOGINED, "true");
4248

43-
// TODO: redirect 로직 구체적으로 추가
44-
router.replace(PATH.HOME);
49+
router.replace(redirectUrl || PATH.HOME);
50+
safeLocalStorage.remove(REDIRECT_URL_KEY);
4551
} catch (error) {
4652
safeLocalStorage.set(TOKEN_KEY, (error as Error).message);
4753
router.replace(PATH.SIGNUP);
@@ -50,7 +56,7 @@ const AuthPage = () => {
5056
// 인증 코드가 없는 경우 로그인 페이지로 리다이렉트
5157
router.replace(PATH.LOGIN);
5258
}
53-
}, [authorizationCode, mutateAsync, router, socialType]);
59+
}, [authorizationCode, mutateAsync, router, socialType, redirectUrl]);
5460

5561
useEffect(() => {
5662
handleLogin();

apps/ticket/src/shared/constants/storage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ export const TOKEN_KEY = "token";
22
export const SOCIAL_LOGIN_TYPE_KEY = "socialType";
33

44
export const IS_LOGINED = "PERMIT_isLogined";
5+
6+
export const REDIRECT_URL_KEY = "PERMIT_isRedirectUrl";

apps/ticket/src/shared/hooks/useOAuth/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1+
import { useSearchParams } from "next/navigation";
2+
13
import { safeLocalStorage } from "@/lib/storage";
2-
import { SOCIAL_LOGIN_TYPE_KEY } from "@/shared/constants/storage";
4+
import { REDIRECT_URL_KEY, SOCIAL_LOGIN_TYPE_KEY } from "@/shared/constants/storage";
35

46
import { GOOGLE_LOGIN_URL, KAKAO_LOGIN_URL } from "./constants";
57
import { SOCIAL_LOGIN_TYPE, SocialLoginType } from "./types";
68

79
export const useOAuth = () => {
10+
const redirectUrl = useSearchParams().get("redirectUrl") ?? "/";
11+
812
const handleLogin = (socialType: SocialLoginType) => {
13+
safeLocalStorage.set(REDIRECT_URL_KEY, redirectUrl);
14+
safeLocalStorage.set(SOCIAL_LOGIN_TYPE_KEY, socialType);
15+
916
if (socialType === SOCIAL_LOGIN_TYPE.KAKAO) {
1017
kakaoLogin();
1118
} else if (socialType === SOCIAL_LOGIN_TYPE.GOOGLE) {
1219
googleLogin();
1320
}
14-
15-
safeLocalStorage.set(SOCIAL_LOGIN_TYPE_KEY, socialType);
1621
};
1722

1823
const kakaoLogin = () => {

0 commit comments

Comments
 (0)