Skip to content

Commit 0466a0d

Browse files
authored
Merge pull request #268 from manNomi/feature/login-logic
Feat : 로그인 대폭 수정 및 커뮤니티 썸네일 구현
2 parents a107463 + 3311dea commit 0466a0d

72 files changed

Lines changed: 748 additions & 962 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎package-lock.json‎

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@
2020
"@stomp/stompjs": "^7.1.1",
2121
"@tanstack/react-query": "^5.84.1",
2222
"@tanstack/react-query-devtools": "^5.84.1",
23+
"@types/js-cookie": "^3.0.6",
2324
"axios": "^1.6.7",
2425
"class-variance-authority": "^0.7.1",
2526
"clsx": "^2.1.1",
2627
"critters": "^0.0.23",
2728
"firebase": "^10.7.2",
2829
"firebase-admin": "^12.0.0",
30+
"js-cookie": "^3.0.5",
31+
"linkify-react": "^4.3.2",
32+
"linkifyjs": "^4.3.2",
2933
"lucide-react": "^0.479.0",
3034
"next": "^14.2.4",
3135
"react": "^18",
3236
"react-hook-form": "^7.60.0",
33-
"react-linkify": "^1.0.0-alpha",
3437
"sockjs-client": "^1.6.1",
3538
"tailwind-merge": "^3.0.2",
3639
"tailwindcss-animate": "^1.0.7",

‎public/svgs/home/index.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import IconCloud from "./cloud.svg";
22
import IconGraduationCap from "./graduation-cap.svg";
33
import IconIdCard from "./id-card.svg";
4+
import IconLoveLetter from "./love-letter.svg";
45
import IconMagnifyingGlass from "./magnifying-glass.svg";
56
import IconMuseum from "./museum.svg";
67
import IconPaper from "./paper.svg";
78
import IconRightArrow from "./right-arrow.svg";
89

9-
export { IconCloud, IconGraduationCap, IconIdCard, IconMagnifyingGlass, IconMuseum, IconPaper, IconRightArrow };
10+
export {
11+
IconCloud,
12+
IconGraduationCap,
13+
IconIdCard,
14+
IconMagnifyingGlass,
15+
IconMuseum,
16+
IconPaper,
17+
IconRightArrow,
18+
IconLoveLetter,
19+
};

‎public/svgs/home/love-letter.svg‎

Lines changed: 9 additions & 0 deletions
Loading

‎src/api/auth/client/useDeleteUserAccount.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import { useRouter } from "next/navigation";
22

33
import { AxiosResponse } from "axios";
44

5+
import { removeIsPrevLoginCookie } from "@/utils/authCookieUtils";
56
import { axiosInstance } from "@/utils/axiosInstance";
6-
import { removeRefreshTokenFromLS } from "@/utils/localStorageUtils";
7+
import { removeAccessTokenToLS } from "@/utils/localStorageUtils";
78

8-
import { clearAccessToken } from "@/lib/zustand/useTokenStore";
9+
import useAuthStore from "@/lib/zustand/useAuthStore";
910
import { useMutation, useQueryClient } from "@tanstack/react-query";
1011

1112
export const deleteUserAccount = (): Promise<AxiosResponse<null>> => axiosInstance.delete("/auth/quit");
1213

1314
const useDeleteUserAccount = () => {
1415
const router = useRouter();
16+
const { clearAccessToken } = useAuthStore();
1517
const queryClient = useQueryClient(); // 쿼리 캐시 관리를 위해 클라이언트 인스턴스를 가져옵니다.
1618

1719
return useMutation({
@@ -22,7 +24,8 @@ const useDeleteUserAccount = () => {
2224
},
2325
onSuccess: () => {
2426
clearAccessToken();
25-
removeRefreshTokenFromLS();
27+
removeIsPrevLoginCookie(); // isPrevLogin 쿠키 제거
28+
removeAccessTokenToLS();
2629
queryClient.clear();
2730
},
2831
onError: (error) => {

‎src/api/auth/client/usePostAppleAuth.ts‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { useRouter } from "next/navigation";
22

33
import { AxiosResponse } from "axios";
44

5+
import { getTokenExpirationSeconds, setIsPrevLoginCookie } from "@/utils/authCookieUtils";
6+
import { isCookieLoginEnabled } from "@/utils/authUtils";
57
import { publicAxiosInstance } from "@/utils/axiosInstance";
6-
import { isCookieLoginEnabled } from "@/utils/localStorage";
7-
import { saveRefreshTokenToLS } from "@/utils/localStorageUtils";
8+
import { saveAccessTokenToLS } from "@/utils/localStorageUtils";
89

9-
import { setAccessToken } from "@/lib/zustand/useTokenStore";
10+
import useAuthStore from "@/lib/zustand/useAuthStore";
1011
import { useMutation } from "@tanstack/react-query";
1112

1213
// Apple
@@ -43,11 +44,20 @@ const usePostAppleAuth = () => {
4344

4445
if (data.isRegistered) {
4546
// 기존 회원일 시 - 토큰 저장하고 홈으로 이동
46-
setAccessToken(data.accessToken);
47+
useAuthStore.getState().setAccessToken(data.accessToken);
48+
49+
// isPrevLogin 쿠키 설정 (성능 최적화를 위해)
50+
const expirationSeconds = getTokenExpirationSeconds(data.accessToken);
51+
if (expirationSeconds && expirationSeconds > 0) {
52+
setIsPrevLoginCookie(expirationSeconds);
53+
} else {
54+
// 토큰 파싱에 실패한 경우 기본값으로 1시간 설정
55+
setIsPrevLoginCookie(3600); // 1 hour
56+
}
4757

4858
// 로컬스토리지 모드일 때만 리프레시 토큰을 로컬스토리지에 저장
49-
if (!isCookieLoginEnabled() && data.refreshToken) {
50-
saveRefreshTokenToLS(data.refreshToken);
59+
if (!isCookieLoginEnabled()) {
60+
saveAccessTokenToLS(data.accessToken);
5161
}
5262

5363
router.push("/");
@@ -56,7 +66,7 @@ const usePostAppleAuth = () => {
5666
router.push(`/sign-up?token=${data.signUpToken}`);
5767
}
5868
},
59-
onError: (error) => {
69+
onError: () => {
6070
alert("애플 로그인 중 오류가 발생했습니다. 다시 시도해주세요.");
6171
router.push("/login");
6272
},

‎src/api/auth/client/usePostEmailAuth.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { useRouter } from "next/navigation";
22

33
import { AxiosResponse } from "axios";
44

5+
import { getTokenExpirationSeconds, setIsPrevLoginCookie } from "@/utils/authCookieUtils";
6+
import { isCookieLoginEnabled } from "@/utils/authUtils";
57
import { publicAxiosInstance } from "@/utils/axiosInstance";
6-
import { isCookieLoginEnabled } from "@/utils/localStorage";
7-
import { saveRefreshTokenToLS } from "@/utils/localStorageUtils";
8+
import { saveAccessTokenToLS } from "@/utils/localStorageUtils";
89

9-
import { setAccessToken } from "@/lib/zustand/useTokenStore";
10+
import useAuthStore from "@/lib/zustand/useAuthStore";
1011
import { useMutation } from "@tanstack/react-query";
1112

1213
interface UsePostEmailSignInResponse {
@@ -24,6 +25,7 @@ const postEmailAuth = ({ email, password }: LoginRequest): Promise<AxiosResponse
2425

2526
const usePostEmailAuth = () => {
2627
const router = useRouter();
28+
const { setAccessToken } = useAuthStore();
2729
return useMutation({
2830
mutationFn: postEmailAuth,
2931
onSuccess: (data) => {
@@ -32,15 +34,24 @@ const usePostEmailAuth = () => {
3234
// 액세스 토큰은 항상 Zustand 스토어에 저장
3335
setAccessToken(accessToken);
3436

37+
// isPrevLogin 쿠키 설정 (성능 최적화를 위해)
38+
const expirationSeconds = getTokenExpirationSeconds(accessToken);
39+
if (expirationSeconds && expirationSeconds > 0) {
40+
setIsPrevLoginCookie(expirationSeconds);
41+
} else {
42+
// 토큰 파싱에 실패한 경우 기본값으로 1시간 설정
43+
setIsPrevLoginCookie(3600); // 1 hour
44+
}
45+
3546
// 로컬스토리지 모드일 때만 리프레시 토큰을 로컬스토리지에 저장
3647
// 쿠키 모드일 때는 서버에서 HTTP-only 쿠키로 자동 설정됨
37-
if (!isCookieLoginEnabled() && refreshToken) {
38-
saveRefreshTokenToLS(refreshToken);
48+
if (!isCookieLoginEnabled() && accessToken) {
49+
saveAccessTokenToLS(accessToken);
3950
}
4051

4152
router.replace("/"); // 로그인 성공 후 홈으로 리다이렉트
4253
},
43-
onError: (error) => {
54+
onError: () => {
4455
alert("이메일 또는 비밀번호가 올바르지 않습니다. 다시 시도해주세요.");
4556
},
4657
});

‎src/api/auth/client/usePostKakaoAuth.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { useRouter } from "next/navigation";
22

33
import { AxiosResponse } from "axios";
44

5+
import { getTokenExpirationSeconds, setIsPrevLoginCookie } from "@/utils/authCookieUtils";
6+
import { isCookieLoginEnabled } from "@/utils/authUtils";
57
import { publicAxiosInstance } from "@/utils/axiosInstance";
6-
import { isCookieLoginEnabled } from "@/utils/localStorage";
7-
import { saveRefreshTokenToLS } from "@/utils/localStorageUtils";
8+
import { saveAccessTokenToLS } from "@/utils/localStorageUtils";
89

9-
import { setAccessToken } from "@/lib/zustand/useTokenStore";
10+
import useAuthStore from "@/lib/zustand/useAuthStore";
1011
import { useMutation } from "@tanstack/react-query";
1112

1213
// Kakao
@@ -34,6 +35,7 @@ const postKakaoAuth = ({
3435
publicAxiosInstance.post("/auth/kakao", { code });
3536

3637
const usePostKakaoAuth = () => {
38+
const { setAccessToken } = useAuthStore();
3739
const router = useRouter();
3840

3941
return useMutation({
@@ -45,9 +47,18 @@ const usePostKakaoAuth = () => {
4547
// 기존 회원일 시 - 토큰 저장하고 홈으로 이동
4648
setAccessToken(data.accessToken);
4749

50+
// isPrevLogin 쿠키 설정 (성능 최적화를 위해)
51+
const expirationSeconds = getTokenExpirationSeconds(data.accessToken);
52+
if (expirationSeconds && expirationSeconds > 0) {
53+
setIsPrevLoginCookie(expirationSeconds);
54+
} else {
55+
// 토큰 파싱에 실패한 경우 기본값으로 1시간 설정
56+
setIsPrevLoginCookie(3600); // 1 hour
57+
}
58+
4859
// 로컬스토리지 모드일 때만 리프레시 토큰을 로컬스토리지에 저장
49-
if (!isCookieLoginEnabled() && data.refreshToken) {
50-
saveRefreshTokenToLS(data.refreshToken);
60+
if (!isCookieLoginEnabled() && data.accessToken) {
61+
saveAccessTokenToLS(data.accessToken);
5162
}
5263

5364
router.push("/");
@@ -56,7 +67,7 @@ const usePostKakaoAuth = () => {
5667
router.push(`/sign-up?token=${data.signUpToken}`);
5768
}
5869
},
59-
onError: (error) => {
70+
onError: () => {
6071
alert("카카오 로그인 중 오류가 발생했습니다. 다시 시도해주세요.");
6172
router.push("/login");
6273
},

‎src/api/auth/client/usePostLogout.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ import { useRouter } from "next/navigation";
22

33
import { AxiosResponse } from "axios";
44

5+
import { removeIsPrevLoginCookie } from "@/utils/authCookieUtils";
6+
import { isCookieLoginEnabled } from "@/utils/authUtils";
57
import { axiosInstance } from "@/utils/axiosInstance";
6-
import { removeRefreshTokenFromLS } from "@/utils/localStorageUtils";
8+
import { removeAccessTokenToLS } from "@/utils/localStorageUtils";
79

8-
import { clearAccessToken } from "@/lib/zustand/useTokenStore";
10+
import useAuthStore from "@/lib/zustand/useAuthStore";
911
import { useMutation, useQueryClient } from "@tanstack/react-query";
1012

1113
export const postLogout = (): Promise<AxiosResponse<null>> => axiosInstance.post("/auth/sign-out");
1214

1315
const usePostLogout = () => {
1416
const router = useRouter();
17+
const { clearAccessToken } = useAuthStore();
1518
const queryClient = useQueryClient(); // 쿼리 캐시 관리를 위해 클라이언트 인스턴스를 가져옵니다.
1619

1720
return useMutation({
@@ -22,7 +25,8 @@ const usePostLogout = () => {
2225
},
2326
onSuccess: () => {
2427
clearAccessToken();
25-
removeRefreshTokenFromLS();
28+
removeIsPrevLoginCookie(); // isPrevLogin 쿠키 제거
29+
removeAccessTokenToLS();
2630
queryClient.clear();
2731
},
2832
onError: (error) => {

0 commit comments

Comments
 (0)