@daeryun/dr_components 0.4.21 → 0.4.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/page/Login/_api/withdraw.js +2 -1
- package/dist/components/page/Login/_api/withdraw.ts +2 -1
- package/dist/components/page/Login/_hooks/useAppLoginDetect.d.ts +4 -2
- package/dist/components/page/Login/_hooks/useAppLoginDetect.js +60 -15
- package/dist/components/page/Login/_hooks/useAppLoginDetect.ts +75 -16
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -11,7 +11,8 @@ import Fetch from '../_fetch/fetch';
|
|
|
11
11
|
export const withdraw = (_a) => __awaiter(void 0, [_a], void 0, function* ({ bodyData }) {
|
|
12
12
|
try {
|
|
13
13
|
const res = yield Fetch('/api/lawfirm/app/user', {
|
|
14
|
-
method: 'DELETE'
|
|
14
|
+
method: 'DELETE',
|
|
15
|
+
body: JSON.stringify(bodyData)
|
|
15
16
|
});
|
|
16
17
|
if (res.result) {
|
|
17
18
|
yield fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/token`, {
|
|
@@ -3,7 +3,8 @@ import Fetch from '../_fetch/fetch';
|
|
|
3
3
|
export const withdraw = async ({ bodyData }: { bodyData: { reason: string } }) => {
|
|
4
4
|
try {
|
|
5
5
|
const res = await Fetch('/api/lawfirm/app/user', {
|
|
6
|
-
method: 'DELETE'
|
|
6
|
+
method: 'DELETE',
|
|
7
|
+
body: JSON.stringify(bodyData)
|
|
7
8
|
});
|
|
8
9
|
if (res.result) {
|
|
9
10
|
await fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/token`, {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ILoginInfo } from '../_types/login';
|
|
3
|
+
export declare const checkAppLoginDetect: (userInfo: ILoginInfo, setUserInfo: React.Dispatch<React.SetStateAction<ILoginInfo>>, isThirdCookie: boolean) => Promise<void>;
|
|
4
|
+
declare const useAppLoginDetect: (userInfo: ILoginInfo, pathname: string, setUserInfo: React.Dispatch<React.SetStateAction<ILoginInfo>>) => void;
|
|
3
5
|
export default useAppLoginDetect;
|
|
@@ -10,22 +10,57 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { useEffect } from 'react';
|
|
11
11
|
import { fetchAuthCallback } from '../_api/fetchAuthCallback';
|
|
12
12
|
import { deleteToken, getToken } from '../_api/token';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
import checkThirdPartyCookie from '../_api/checkThirdPartyCookie';
|
|
14
|
+
import { fetchUserData } from '../_api/fetchUserData';
|
|
15
|
+
export const checkAppLoginDetect = (userInfo, setUserInfo, isThirdCookie) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
// if (!isLogin) return;
|
|
17
|
+
const nullData = { name: '', isLogin: false, email: '', provider: '' };
|
|
16
18
|
try {
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
if (userInfo.isLogin) {
|
|
20
|
+
if (isThirdCookie) {
|
|
21
|
+
const result = yield fetchAuthCallback();
|
|
22
|
+
if (!(result === null || result === void 0 ? void 0 : result.result) || !(result === null || result === void 0 ? void 0 : result.jwt)) {
|
|
23
|
+
yield deleteToken();
|
|
24
|
+
setUserInfo(nullData);
|
|
25
|
+
window.location.href = '/';
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
setUserInfo(userInfo);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//
|
|
32
|
+
else {
|
|
33
|
+
const result = yield getToken();
|
|
34
|
+
if (!result) {
|
|
35
|
+
yield deleteToken();
|
|
36
|
+
setUserInfo(nullData);
|
|
37
|
+
window.location.href = '/';
|
|
38
|
+
}
|
|
22
39
|
}
|
|
23
40
|
}
|
|
41
|
+
// 비로그인의 경우
|
|
24
42
|
else {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
if (isThirdCookie) {
|
|
44
|
+
const result = yield fetchAuthCallback();
|
|
45
|
+
if (result.result && result.jwt) {
|
|
46
|
+
// 토큰 생성
|
|
47
|
+
const createResult = yield createTokenAndFetchUser(result.jwt);
|
|
48
|
+
if (createResult) {
|
|
49
|
+
const userData = yield fetchUserData();
|
|
50
|
+
setUserInfo(userData);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
setUserInfo(userInfo);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//
|
|
57
|
+
else {
|
|
58
|
+
setUserInfo(userInfo);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// 쿠키 차단의 경우
|
|
62
|
+
else {
|
|
63
|
+
setUserInfo(userInfo);
|
|
29
64
|
}
|
|
30
65
|
}
|
|
31
66
|
}
|
|
@@ -34,12 +69,22 @@ export const checkAppLoginDetect = (isLogin, isThirdCookie) => __awaiter(void 0,
|
|
|
34
69
|
}
|
|
35
70
|
});
|
|
36
71
|
// useEffect에서 올바르게 사용
|
|
37
|
-
const useAppLoginDetect = (
|
|
72
|
+
const useAppLoginDetect = (userInfo, pathname, setUserInfo) => {
|
|
38
73
|
useEffect(() => {
|
|
39
74
|
const checkLogin = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
yield
|
|
75
|
+
const isCookie = yield checkThirdPartyCookie();
|
|
76
|
+
yield checkAppLoginDetect(userInfo, setUserInfo, isCookie);
|
|
41
77
|
});
|
|
42
78
|
checkLogin();
|
|
43
|
-
}, [
|
|
79
|
+
}, [userInfo, pathname]);
|
|
44
80
|
};
|
|
45
81
|
export default useAppLoginDetect;
|
|
82
|
+
const createTokenAndFetchUser = (jwt, cookies) => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const createTokenResult = yield fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/token`, {
|
|
84
|
+
body: JSON.stringify({ jwt }),
|
|
85
|
+
method: 'POST',
|
|
86
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, (cookies !== '' ? { Cookie: cookies } : {})),
|
|
87
|
+
credentials: 'include'
|
|
88
|
+
}).then(res => res.json());
|
|
89
|
+
return createTokenResult.token;
|
|
90
|
+
});
|
|
@@ -1,22 +1,62 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import { fetchAuthCallback } from '../_api/fetchAuthCallback';
|
|
3
3
|
import { deleteToken, getToken } from '../_api/token';
|
|
4
|
+
import checkThirdPartyCookie from '../_api/checkThirdPartyCookie';
|
|
5
|
+
import { fetchUserData } from '../_api/fetchUserData';
|
|
6
|
+
import { ILoginInfo } from '../_types/login';
|
|
4
7
|
|
|
5
|
-
export const checkAppLoginDetect = async (
|
|
6
|
-
|
|
8
|
+
export const checkAppLoginDetect = async (
|
|
9
|
+
userInfo: ILoginInfo,
|
|
10
|
+
setUserInfo: React.Dispatch<React.SetStateAction<ILoginInfo>>,
|
|
11
|
+
isThirdCookie: boolean
|
|
12
|
+
) => {
|
|
13
|
+
// if (!isLogin) return;
|
|
14
|
+
const nullData = { name: '', isLogin: false, email: '', provider: '' };
|
|
7
15
|
|
|
8
16
|
try {
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
if (userInfo.isLogin) {
|
|
18
|
+
if (isThirdCookie) {
|
|
19
|
+
const result = await fetchAuthCallback();
|
|
20
|
+
if (!result?.result || !result?.jwt) {
|
|
21
|
+
await deleteToken();
|
|
22
|
+
setUserInfo(nullData);
|
|
23
|
+
window.location.href = '/';
|
|
24
|
+
} else {
|
|
25
|
+
setUserInfo(userInfo);
|
|
26
|
+
}
|
|
14
27
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
//
|
|
29
|
+
else {
|
|
30
|
+
const result = await getToken();
|
|
31
|
+
if (!result) {
|
|
32
|
+
await deleteToken();
|
|
33
|
+
setUserInfo(nullData);
|
|
34
|
+
window.location.href = '/';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// 비로그인의 경우
|
|
39
|
+
else {
|
|
40
|
+
if (isThirdCookie) {
|
|
41
|
+
const result = await fetchAuthCallback();
|
|
42
|
+
if (result.result && result.jwt) {
|
|
43
|
+
// 토큰 생성
|
|
44
|
+
const createResult = await createTokenAndFetchUser(result.jwt);
|
|
45
|
+
if (createResult) {
|
|
46
|
+
const userData = await fetchUserData();
|
|
47
|
+
setUserInfo(userData);
|
|
48
|
+
} else {
|
|
49
|
+
setUserInfo(userInfo);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//
|
|
53
|
+
else {
|
|
54
|
+
setUserInfo(userInfo);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// 쿠키 차단의 경우
|
|
58
|
+
else {
|
|
59
|
+
setUserInfo(userInfo);
|
|
20
60
|
}
|
|
21
61
|
}
|
|
22
62
|
} catch (error) {
|
|
@@ -25,14 +65,33 @@ export const checkAppLoginDetect = async (isLogin: boolean, isThirdCookie: boole
|
|
|
25
65
|
};
|
|
26
66
|
|
|
27
67
|
// useEffect에서 올바르게 사용
|
|
28
|
-
const useAppLoginDetect = (
|
|
68
|
+
const useAppLoginDetect = (
|
|
69
|
+
userInfo: ILoginInfo,
|
|
70
|
+
pathname: string,
|
|
71
|
+
setUserInfo: React.Dispatch<React.SetStateAction<ILoginInfo>>
|
|
72
|
+
) => {
|
|
29
73
|
useEffect(() => {
|
|
30
74
|
const checkLogin = async () => {
|
|
31
|
-
await
|
|
75
|
+
const isCookie = await checkThirdPartyCookie();
|
|
76
|
+
await checkAppLoginDetect(userInfo, setUserInfo, isCookie);
|
|
32
77
|
};
|
|
33
78
|
|
|
34
79
|
checkLogin();
|
|
35
|
-
}, [
|
|
80
|
+
}, [userInfo, pathname]);
|
|
36
81
|
};
|
|
37
82
|
|
|
38
83
|
export default useAppLoginDetect;
|
|
84
|
+
|
|
85
|
+
const createTokenAndFetchUser = async (jwt: string, cookies?: string) => {
|
|
86
|
+
const createTokenResult = await fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/token`, {
|
|
87
|
+
body: JSON.stringify({ jwt }),
|
|
88
|
+
method: 'POST',
|
|
89
|
+
headers: {
|
|
90
|
+
'Content-Type': 'application/json',
|
|
91
|
+
...(cookies !== '' ? { Cookie: cookies } : {})
|
|
92
|
+
},
|
|
93
|
+
credentials: 'include'
|
|
94
|
+
}).then(res => res.json());
|
|
95
|
+
|
|
96
|
+
return createTokenResult.token;
|
|
97
|
+
};
|