Skip to content

Commit b725a79

Browse files
committed
feat: 소셜로그인 및 회원가입 연결
- 소셜 로그인, 회원가입 시 리디렉션 페이지 연동 완료 - 유저정보 저장 진행 중
1 parent 5ca4f51 commit b725a79

File tree

6 files changed

+76
-15
lines changed

6 files changed

+76
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@tanstack/react-query": "^5.66.0",
2020
"axios": "^1.7.9",
2121
"gsap": "^3.12.7",
22+
"immer": "^10.1.1",
2223
"react": "^18.3.1",
2324
"react-dom": "^18.3.1",
2425
"react-router": "^7.1.5",

pnpm-lock.yaml

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

src/apis/auth.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// import useAuthStore from '@/stores/authStore';
2+
3+
// import client from './client';
4+
5+
type LoginType = 'kakao' | 'naver' | 'google';
6+
export const socialLogin = (loginType: LoginType) => {
7+
// eslint-disable-next-line react-hooks/rules-of-hooks
8+
// const { setUserId, setZipCode, login } = useAuthStore.getState();
9+
window.location.href = `http://13.209.132.150:8081/oauth2/authorization/${loginType}`;
10+
};
11+

src/apis/client.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ const client = axios.create({
44
baseURL: import.meta.env.VITE_API_URL,
55
});
66

7-
// client.interceptors.request.use(
8-
// (config) => {
9-
// const token = localStorage.getItem('authToken');
10-
// if (token) {
11-
// config.headers['Authorization'] = `Bearer ${token}`;
12-
// }
13-
// return config;
14-
// },
15-
// (error) => {
16-
// //TODO: 에러처리
17-
// return Promise.reject(error);
18-
// },
19-
// );
7+
client.interceptors.request.use(
8+
(config) => {
9+
const token = localStorage.getItem('authToken');
10+
if (token) {
11+
config.headers['Authorization'] = `Bearer ${token}`;
12+
}
13+
return config;
14+
},
15+
(error) => {
16+
//TODO: 에러처리
17+
return Promise.reject(error);
18+
},
19+
);
2020

2121
export default client;

src/pages/Login/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
import { socialLogin } from '@/apis/auth';
12
import { GoogleIcon, KakaoIcon, NaverIcon, StampIcon } from '@/assets/icons';
23

34
import Background from './components/Background';
45

56
const LoginPage = () => {
7+
type LoginType = 'kakao' | 'naver' | 'google';
8+
9+
const handleLogin = (loginType: LoginType) => {
10+
socialLogin(loginType);
11+
};
612
return (
713
<>
814
<main className="mt-10 flex grow flex-col items-center justify-between">
@@ -22,20 +28,23 @@ const LoginPage = () => {
2228
type="button"
2329
className="rounded-full bg-[#03C75A] p-3.5"
2430
aria-label="네이버 로그인"
31+
onClick={() => handleLogin('naver')}
2532
>
2633
<NaverIcon />
2734
</button>
2835
<button
2936
type="button"
3037
className="rounded-full bg-[#FEE500] p-3.5"
3138
aria-label="카카오 로그인"
39+
onClick={() => handleLogin('kakao')}
3240
>
3341
<KakaoIcon />
3442
</button>
3543
<button
3644
type="button"
3745
className="border-gray-5 rounded-full border bg-white p-3.5"
3846
aria-label="구글 로그인"
47+
onClick={() => handleLogin('google')}
3948
>
4049
<GoogleIcon />
4150
</button>

src/stores/authStore.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { create } from 'zustand';
2+
import { persist, createJSONStorage } from 'zustand/middleware';
3+
4+
interface AuthStore {
5+
isLoggedIn: boolean;
6+
userId: number | null;
7+
zipCode: string;
8+
login: () => void;
9+
logout: () => void;
10+
setUserId: (userId: number) => void;
11+
setZipCode: (zipCode: string) => void;
12+
}
13+
const useAuthStore = create(
14+
persist<AuthStore>(
15+
(set) => ({
16+
isLoggedIn: false,
17+
userId: null,
18+
zipCode: '',
19+
login: () => set({ isLoggedIn: true }),
20+
logout: () => set({ isLoggedIn: false, userId: null, zipCode: '' }),
21+
setUserId: (userId) => set({ userId: userId }),
22+
setZipCode: (zipCode) => set({ zipCode: zipCode }),
23+
}),
24+
{
25+
name: 'userInfo',
26+
storage: createJSONStorage(() => sessionStorage),
27+
},
28+
),
29+
);
30+
31+
export default useAuthStore;

0 commit comments

Comments
 (0)