Skip to content

Commit eb6cc62

Browse files
committed
test: 로그인 테스트용 임시 커밋
1 parent b8f7c22 commit eb6cc62

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

src/apis/auth.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import useAuthStore from '@/stores/authStore';
2+
23
import client from './client';
34

45
type LoginType = 'kakao' | 'naver' | 'google';
56
export const socialLogin = (loginType: LoginType) => {
6-
// eslint-disable-next-line react-hooks/rules-of-hooks
7-
// const { setUserId, setZipCode, login } = useAuthStore.getState();
8-
97
window.location.href = `http://13.209.132.150:8081/oauth2/authorization/${loginType}`;
108
};
119

1210
export const logout = async () => {
1311
const { accessToken } = useAuthStore.getState();
12+
1413
try {
1514
const response = await client.post(`/api/logout`, {
1615
Authorization: { token: `Bearer ${accessToken}` },
@@ -23,13 +22,11 @@ export const logout = async () => {
2322
}
2423
};
2524

26-
//임시 코드
2725
export const getUserToken = async (stateToken: string) => {
2826
try {
2927
const response = await client.get(`/api/auth/token?state=${stateToken}`);
3028
if (!response) throw new Error('getUserToken: Error while fetching user token');
31-
const userInfo = response.headers['authorization'];
32-
29+
const userInfo = response.data;
3330
if (userInfo) {
3431
return userInfo;
3532
}
@@ -38,7 +35,9 @@ export const getUserToken = async (stateToken: string) => {
3835
}
3936
};
4037

41-
export const getZipCode = async (accessToken: string) => {
38+
export const getZipCode = async () => {
39+
const { accessToken, userId, zipCode, isLoggedIn } = useAuthStore.getState();
40+
4241
try {
4342
const response = await client.get(`/members/zipCode`, {
4443
headers: {
@@ -47,6 +46,7 @@ export const getZipCode = async (accessToken: string) => {
4746
});
4847
if (!response) throw new Error('getZipCode: no response data');
4948
console.log(response);
49+
console.log('UserInfo', 'Id:', userId, 'isLoggedIn:', isLoggedIn, 'zipCode', zipCode);
5050
return response;
5151
} catch (error) {
5252
console.error(error);

src/pages/Auth/index.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { useEffect, useState } from 'react';
1+
import { useEffect } from 'react';
22
import { useNavigate } from 'react-router';
33

44
import { getUserToken } from '@/apis/auth';
55
import useAuthStore from '@/stores/authStore';
66

77
const AuthCallbackPage = () => {
88
const stateToken = new URLSearchParams(window.location.search).get('state');
9-
const { setUserId, setZipCode, setAccessToken, zipCode } = useAuthStore.getState();
10-
const [role, setRole] = useState<string>('');
9+
const redirectURL = new URLSearchParams(window.location.search).get('redirect');
10+
11+
const { setUserId, setZipCode, setAccessToken, zipCode } = useAuthStore();
1112

1213
const navigate = useNavigate();
1314

@@ -18,9 +19,7 @@ const AuthCallbackPage = () => {
1819

1920
const accessToken = userInfo.match(/Bearer\s+(\S+)/);
2021
if (accessToken) setAccessToken(accessToken[1]);
21-
22-
const role = userInfo.match(/Role=([\w-]+)/);
23-
if (role) setRole(role);
22+
console.log('token', accessToken);
2423

2524
const userId = userInfo.match(/UserId=(\d+)/);
2625
if (userId) setUserId(userId[1]);
@@ -32,19 +31,18 @@ const AuthCallbackPage = () => {
3231
}
3332
};
3433

35-
const redirection = () => {
36-
if (role === 'admin') navigate('/report');
37-
else {
38-
if (!zipCode) navigate('/onboarding');
39-
else navigate('/');
40-
}
41-
};
34+
// const redirection = () => {
35+
// if(redirectURL === 'onboarding') navigate('/onboarding');
36+
// else if(redirectURL === 'home') navigate('/');
37+
// else navigate('/notFound');
38+
// };
4239

4340
useEffect(() => {
4441
if (stateToken) {
4542
setUserInfo(stateToken as string);
46-
redirection();
47-
} else navigate('/notFound');
43+
// redirection();
44+
}
45+
// else navigate('/notFound');
4846
}, []);
4947
return <div></div>;
5048
};

0 commit comments

Comments
 (0)