Skip to content

Commit 0826746

Browse files
authored
Merge pull request #241 from manNomi/refactor/login_page
refactor : login 페이지
2 parents 46a8edc + f9edea9 commit 0826746

17 files changed

Lines changed: 343 additions & 268 deletions

public/svgs/auth/apple-logo.svg

Lines changed: 6 additions & 0 deletions
Loading

public/svgs/auth/email-icon.svg

Lines changed: 6 additions & 0 deletions
Loading

public/svgs/auth/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
import IconAppleLogo from "./apple-logo.svg";
2+
import IconEmailIcon from "./email-icon.svg";
3+
import IconKakaoLogo from "./kakao-logo.svg";
14
import IconPrepare1 from "./prepare-1.svg";
25
import IconPrepare2 from "./prepare-2.svg";
36
import IconPrepare3 from "./prepare-3.svg";
47
import IconSignupProfileImage from "./signup-profile-image.svg";
58

6-
export { IconPrepare1, IconPrepare2, IconPrepare3, IconSignupProfileImage };
9+
export {
10+
IconPrepare1,
11+
IconPrepare2,
12+
IconPrepare3,
13+
IconSignupProfileImage,
14+
IconKakaoLogo,
15+
IconAppleLogo,
16+
IconEmailIcon,
17+
};
18+
19+
// Login page icons

public/svgs/auth/kakao-logo.svg

Lines changed: 15 additions & 0 deletions
Loading
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { useRouter } from "next/navigation";
2+
3+
import { AxiosResponse } from "axios";
4+
5+
import { publicAxiosInstance } from "@/utils/axiosInstance";
6+
7+
import { setAccessToken } from "@/lib/zustand/useTokenStore";
8+
import { useMutation } from "@tanstack/react-query";
9+
10+
// Apple
11+
export interface RegisteredAppleAuthResponse {
12+
isRegistered: true;
13+
accessToken: string;
14+
refreshToken: string;
15+
}
16+
17+
export interface UnregisteredAppleAuthResponse {
18+
isRegistered: false;
19+
nickname: null;
20+
email: string;
21+
profileImageUrl: null;
22+
signUpToken: string;
23+
}
24+
25+
interface AppleAuthRequest {
26+
code: string;
27+
}
28+
29+
type AppleAuthResponse = RegisteredAppleAuthResponse | UnregisteredAppleAuthResponse;
30+
31+
const postAppleAuth = ({ code }: AppleAuthRequest): Promise<AxiosResponse<AppleAuthResponse>> =>
32+
publicAxiosInstance.post("/auth/apple", { code });
33+
34+
const usePostAppleAuth = () => {
35+
const router = useRouter();
36+
37+
return useMutation({
38+
mutationFn: postAppleAuth,
39+
onSuccess: (response) => {
40+
const { data } = response;
41+
42+
if (data.isRegistered) {
43+
// 기존 회원일 시 - 토큰 저장하고 홈으로 이동
44+
setAccessToken(data.accessToken);
45+
router.push("/");
46+
} else {
47+
// 새로운 회원일 시 - 회원가입 페이지로 이동
48+
router.push(`/sign-up?token=${data.signUpToken}`);
49+
}
50+
},
51+
onError: (error) => {
52+
alert("애플 로그인 중 오류가 발생했습니다. 다시 시도해주세요.");
53+
router.push("/login");
54+
},
55+
});
56+
};
57+
58+
export default usePostAppleAuth;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { AxiosResponse } from "axios";
2+
3+
import { publicAxiosInstance } from "@/utils/axiosInstance";
4+
5+
import { setAccessToken } from "@/lib/zustand/useTokenStore";
6+
import { useMutation } from "@tanstack/react-query";
7+
8+
interface UsePostEmailSignInResponse {
9+
accessToken: string;
10+
refreshToken: string;
11+
}
12+
13+
interface LoginRequest {
14+
email: string;
15+
password: string;
16+
}
17+
18+
const postEmailAuth = ({ email, password }: LoginRequest): Promise<AxiosResponse<UsePostEmailSignInResponse>> =>
19+
publicAxiosInstance.post("/auth/email/sign-in", { email, password });
20+
21+
const usePostEmailAuth = () => {
22+
return useMutation({
23+
mutationFn: postEmailAuth,
24+
onSuccess: (data) => {
25+
const { accessToken } = data.data;
26+
setAccessToken(accessToken);
27+
},
28+
});
29+
};
30+
export default usePostEmailAuth;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { useRouter } from "next/navigation";
2+
3+
import { AxiosResponse } from "axios";
4+
5+
import { publicAxiosInstance } from "@/utils/axiosInstance";
6+
7+
import { setAccessToken } from "@/lib/zustand/useTokenStore";
8+
import { useMutation } from "@tanstack/react-query";
9+
10+
// Kakao
11+
interface RegisteredKakaoAuthResponse {
12+
isRegistered: true;
13+
accessToken: string;
14+
refreshToken: string;
15+
}
16+
17+
interface UnregisteredKakaoAuthReponse {
18+
isRegistered: false;
19+
nickname: string;
20+
email: string;
21+
profileImageUrl: string;
22+
signUpToken: string;
23+
}
24+
25+
interface KakaoAuthRequest {
26+
code: string;
27+
}
28+
29+
const postKakaoAuth = ({
30+
code,
31+
}: KakaoAuthRequest): Promise<AxiosResponse<RegisteredKakaoAuthResponse | UnregisteredKakaoAuthReponse>> =>
32+
publicAxiosInstance.post("/auth/kakao", { code });
33+
34+
const usePostKakaoAuth = () => {
35+
const router = useRouter();
36+
37+
return useMutation({
38+
mutationFn: postKakaoAuth,
39+
onSuccess: (response) => {
40+
const { data } = response;
41+
42+
if (data.isRegistered) {
43+
// 기존 회원일 시 - 토큰 저장하고 홈으로 이동
44+
setAccessToken(data.accessToken);
45+
router.push("/");
46+
} else {
47+
// 새로운 회원일 시 - 회원가입 페이지로 이동
48+
router.push(`/sign-up?token=${data.signUpToken}`);
49+
}
50+
},
51+
onError: (error) => {
52+
alert("카카오 로그인 중 오류가 발생했습니다. 다시 시도해주세요.");
53+
router.push("/login");
54+
},
55+
});
56+
};
57+
58+
export default usePostKakaoAuth;

src/app/login/AppleLoginButton.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/app/login/EmailSignUpButton.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/app/login/KakaoLoginButton.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)