Skip to content

Commit df9e340

Browse files
authored
Merge pull request #329 from JEOLLOGA/develop
[DEPLOY] dev to main
2 parents 5e5be45 + 26d4d6f commit df9e340

File tree

8 files changed

+55
-69
lines changed

8 files changed

+55
-69
lines changed

next.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ const nextConfig: NextConfig = {
1111
},
1212

1313
images: {
14-
domains: ['noms.templestay.com', 'www.templestay.com', 'blogthumb.pstatic.net'],
14+
domains: [
15+
'noms.templestay.com',
16+
'www.templestay.com',
17+
'blogthumb.pstatic.net',
18+
'phinf.pstatic.net',
19+
],
1520
},
1621

1722
webpack(config) {

src/apis/auth/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export const useGetKakaoLogin = () => {
1010
mutationFn: ({ code }: { code: string }) => getKakaoLogin(code),
1111
onSuccess: (response) => {
1212
const userNickname = response.data.data.nickname;
13+
const userId = response.data.data.userId;
14+
const userInfo = response.data.data.userInfo;
1315

1416
setCookie('userNickname', userNickname, {
1517
httpOnly: false,
@@ -19,7 +21,9 @@ export const useGetKakaoLogin = () => {
1921
maxAge: 1209600, // 14일
2022
});
2123

22-
if (!userNickname) {
24+
localStorage.setItem('userId', userId);
25+
26+
if (!userInfo) {
2327
router.push('/onboarding');
2428
} else {
2529
router.push('/');

src/apis/instance.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import API_URL from '@apis/env';
44
import MESSAGES from '@apis/messages';
5-
import { getStorageValue } from '@hooks/useLocalStorage';
65
import axios, { isAxiosError } from 'axios';
76
import { deleteCookie } from 'cookies-next';
87

9-
// const API_URL = process.env.NEXT_PUBLIC_APP_BASE_URL as string;
10-
118
// 토큰이 필요없는 api 요청
129
const instance = axios.create({
1310
baseURL: API_URL,
@@ -17,16 +14,6 @@ const instance = axios.create({
1714
},
1815
});
1916

20-
// 토큰이 필요한 api 요청
21-
export const privateInstance = axios.create({
22-
baseURL: API_URL,
23-
headers: {
24-
'Content-Type': 'application/json',
25-
Authorization: `Bearer ${getStorageValue('Authorization')}`,
26-
},
27-
withCredentials: true,
28-
});
29-
3017
export const postRefreshToken = async () => {
3118
try {
3219
const response = await axios.post(
@@ -66,6 +53,19 @@ instance.interceptors.response.use(
6653
return await axios(originRequest);
6754
}
6855
} catch (error) {
56+
await axios
57+
.post(
58+
`${API_URL}/v2/user/auth/logout`,
59+
{},
60+
{
61+
headers: { 'Content-Type': 'application/json' },
62+
withCredentials: true,
63+
},
64+
)
65+
.catch((logoutError) => {
66+
console.error(logoutError);
67+
});
68+
6969
localStorage.clear();
7070
deleteCookie('userNickname');
7171
console.error(error);
@@ -77,10 +77,4 @@ instance.interceptors.response.use(
7777
},
7878
);
7979

80-
// 로그인 상태에 따라 axios인스턴스 선택을 위한 훅
81-
export const getAxiosInstance = () => {
82-
const isLoggedIn = !!getStorageValue('Authorization');
83-
return isLoggedIn ? privateInstance : instance;
84-
};
85-
8680
export default instance;

src/apis/user/axios.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
import instance, { privateInstance } from '@apis/instance';
1+
import instance from '@apis/instance';
22

33
import { OnboardingDataV2, OnboardingResponseV2, UserNicknameResponse } from './type';
44

5-
export const fetchUserNickname = async (userId?: number) => {
6-
if (userId === 0) {
7-
return null;
8-
}
9-
const response = await privateInstance.get<UserNicknameResponse>(`/user/register/success`, {
10-
params: {
11-
userId,
12-
},
13-
});
14-
return response.data;
15-
};
16-
175
export const postOnboardingData = async (data: OnboardingDataV2): Promise<OnboardingResponseV2> => {
186
const response = await instance.post<OnboardingResponseV2>('/v2/user/onboarding', data);
197
return response.data;

src/apis/user/index.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMutation, useQuery } from '@tanstack/react-query';
22

33
import { ApiResponse } from './../response';
4-
import { fetchUserNickname, getMyPage, postOnboardingData } from './axios';
4+
import { getMyPage, postOnboardingData } from './axios';
55
import { MyPageType, OnboardingDataV2, OnboardingResponseV2 } from './type';
66

77
export const usePostOnboardingData = () => {
@@ -18,12 +18,3 @@ export const useGetMyPage = () => {
1818

1919
return { data, isLoading, isError };
2020
};
21-
22-
export const useGetNickname = (userId: number) => {
23-
const { data, isLoading, isError } = useQuery({
24-
queryKey: [userId],
25-
queryFn: () => fetchUserNickname(userId),
26-
});
27-
28-
return { data, isLoading, isError };
29-
};

src/app/onboarding/page.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,29 @@
22

33
export const dynamic = 'force-dynamic';
44

5-
import { useGetNickname, usePostOnboardingData } from '@apis/user';
5+
import { usePostOnboardingData } from '@apis/user';
66
import { OnboardingDataV2 } from '@apis/user/type';
77
import ProgressBar from '@components/common/progressBar/ProgressBar';
8-
import ExceptLayout from '@components/except/exceptLayout/ExceptLayout';
98
import OnboardingSection from '@components/onboarding/OnboardingSection';
109
import { ONBOARDING_STEPS, COMMON_DESCRIPTION } from '@constants/onboarding/onboardingSteps';
1110
import useFunnel from '@hooks/useFunnel';
1211
import { getStorageValue } from '@hooks/useLocalStorage';
1312
import React, { useState, useEffect } from 'react';
13+
import { getCookie } from 'cookies-next';
1414
import useEventLogger from 'src/gtm/hooks/useEventLogger';
1515

1616
import container from './onboardingPage.css';
1717

1818
const OnboardingPage = () => {
19+
const [userName, setUserName] = useState('');
20+
21+
useEffect(() => {
22+
const name = getCookie('userNickname');
23+
if (typeof name === 'string') {
24+
setUserName(name);
25+
}
26+
}, []);
27+
1928
const { Funnel, Step, nextStep, prevStep, currentStep } = useFunnel(
2029
ONBOARDING_STEPS.map((step) => step.id),
2130
'/welcome',
@@ -33,7 +42,6 @@ const OnboardingPage = () => {
3342
const userId = Number(getStorageValue('userId'));
3443
const { mutate: postOnboardingMutate } = usePostOnboardingData();
3544

36-
const { data, isLoading } = useGetNickname(userId);
3745
const [isInitialLoad, setIsInitialLoad] = useState<boolean>(true);
3846
const setVh = () => {
3947
const vh = window.innerHeight * 0.01;
@@ -85,10 +93,6 @@ const OnboardingPage = () => {
8593
});
8694
};
8795

88-
if (isLoading) {
89-
return <ExceptLayout type="loading" />;
90-
}
91-
9296
return (
9397
<div className={container}>
9498
<ProgressBar
@@ -102,9 +106,7 @@ const OnboardingPage = () => {
102106
<Step key={id} name={id}>
103107
<OnboardingSection
104108
id={id}
105-
title={
106-
id === 'ageRange' || id === 'gender' ? [`${data?.nickname}님의`, title] : title
107-
}
109+
title={id === 'ageRange' || id === 'gender' ? [`${userName}님의`, title] : title}
108110
description={COMMON_DESCRIPTION}
109111
options={options}
110112
isNextDisabledInitially={isNextDisabledInitially || false}

src/app/welcome/page.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
'use client';
22

3-
import { useGetNickname } from '@apis/user';
3+
import React, { useState, useEffect } from 'react';
4+
import { getCookie } from 'cookies-next';
5+
import { useRouter } from 'next/navigation';
6+
import useEventLogger from 'src/gtm/hooks/useEventLogger';
7+
48
import PageBottomBtn from '@components/common/button/pageBottomBtn/PageBottomBtn';
59
import LottiePlayer from '@components/common/lottie/LottiePlayer';
6-
import ExceptLayout from '@components/except/exceptLayout/ExceptLayout';
710
import { WELCOME_TEXT } from '@constants/onboarding/onboardingSteps';
8-
import { getStorageValue } from '@hooks/useLocalStorage';
9-
import { useRouter } from 'next/navigation';
10-
import React from 'react';
11-
import useEventLogger from 'src/gtm/hooks/useEventLogger';
1211

1312
import * as styles from './welcomePage.css';
1413

1514
const WelcomePage = () => {
1615
const router = useRouter();
17-
const userId = Number(getStorageValue('userId'));
18-
const { data, isLoading } = useGetNickname(userId);
1916
const { logClickEvent } = useEventLogger('onboarding_end');
2017

21-
if (isLoading) {
22-
return <ExceptLayout type="loading" />;
23-
}
18+
const [userName, setUserName] = useState('');
19+
20+
useEffect(() => {
21+
const name = getCookie('userNickname');
22+
if (typeof name === 'string') {
23+
setUserName(name);
24+
}
25+
}, []);
2426

2527
const handleStart = () => {
2628
router.push('/');
27-
2829
logClickEvent('click_start');
2930
};
3031

3132
return (
3233
<div className={styles.container}>
33-
<h1 className={styles.titleStyle}>{`${data?.nickname}${WELCOME_TEXT}`}</h1>
34+
<h1 className={styles.titleStyle}>{userName ? `${userName}${WELCOME_TEXT}` : ''}</h1>
3435
<div className={styles.lottieStyle}>
3536
<LottiePlayer keyId="onboarding" src="/lotties/onboarding.lottie" />
3637
</div>

src/middleware.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import type { NextRequest } from 'next/server';
44
export const middleware = (request: NextRequest) => {
55
const { pathname } = request.nextUrl;
66

7-
const isLocal = process.env.NODE_ENV === 'development';
8-
const token = request.cookies.get(isLocal ? 'userNickname' : 'accessToken');
7+
// const isLocal = process.env.NODE_ENV === 'development';
8+
// const token = request.cookies.get(isLocal ? 'userNickname' : 'accessToken');
9+
const token = request.cookies.get('userNickname');
910

1011
if ((pathname.startsWith('/myPage') || pathname.startsWith('/wishList')) && !token) {
1112
const loginUrl = new URL('/login', request.url);

0 commit comments

Comments
 (0)