@daeryun/dr_components 0.3.49 → 0.3.51
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/AppPersonal.jsx +2 -1
- package/dist/components/page/Login/AppPersonal.tsx +2 -1
- package/dist/components/page/Login/AppSign.jsx +1 -1
- package/dist/components/page/Login/AppSign.tsx +1 -2
- package/dist/components/page/Login/LoginShareCheckContainer.d.ts +12 -0
- package/dist/components/page/Login/LoginShareCheckContainer.jsx +120 -0
- package/dist/components/page/Login/LoginShareCheckContainer.tsx +131 -0
- package/dist/components/page/Login/_api/logout.js +21 -9
- package/dist/components/page/Login/_api/logout.ts +22 -9
- package/dist/components/page/Login/_hooks/useLogout.d.ts +1 -4
- package/dist/components/page/Login/_hooks/useLogout.js +1 -2
- package/dist/components/page/Login/_hooks/useLogout.ts +1 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -64,7 +64,7 @@ const AppPersonal = ({ layoutClassName = ` mt-[47px] py-[128px] max-lg:mt-[40px
|
|
|
64
64
|
const timerRef = useRef(null); // 초
|
|
65
65
|
const [sendApiCount, setSendApiCount] = useState(0);
|
|
66
66
|
const [isTermModal, setIsTermModal] = useState(false);
|
|
67
|
-
const logoutAction = useAppLogout(
|
|
67
|
+
const logoutAction = useAppLogout();
|
|
68
68
|
const [isModal, setIsModal] = useState(false);
|
|
69
69
|
const [modalObj, setModalObj] = useState({
|
|
70
70
|
title: '',
|
|
@@ -333,6 +333,7 @@ const AppPersonal = ({ layoutClassName = ` mt-[47px] py-[128px] max-lg:mt-[40px
|
|
|
333
333
|
};
|
|
334
334
|
const logoutStart = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
335
335
|
yield logoutAction();
|
|
336
|
+
resetUser();
|
|
336
337
|
});
|
|
337
338
|
const updateInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
338
339
|
// // 이름이 바꼈거나 , 휴대전화 인증을 다시 완료했거나 , 약관 총합 값이 바꼈거나
|
|
@@ -100,7 +100,7 @@ const AppPersonal = ({
|
|
|
100
100
|
const [sendApiCount, setSendApiCount] = useState<number>(0);
|
|
101
101
|
const [isTermModal, setIsTermModal] = useState<boolean>(false);
|
|
102
102
|
|
|
103
|
-
const logoutAction = useAppLogout(
|
|
103
|
+
const logoutAction = useAppLogout();
|
|
104
104
|
|
|
105
105
|
const [isModal, setIsModal] = useState<boolean>(false);
|
|
106
106
|
const [modalObj, setModalObj] = useState<{ title: string; subTitle: string; key: string }>({
|
|
@@ -419,6 +419,7 @@ const AppPersonal = ({
|
|
|
419
419
|
|
|
420
420
|
const logoutStart = async () => {
|
|
421
421
|
await logoutAction();
|
|
422
|
+
resetUser();
|
|
422
423
|
};
|
|
423
424
|
|
|
424
425
|
const updateInfo = async () => {
|
|
@@ -390,7 +390,7 @@ const AppSign = ({ layoutClassName = `mt-[47px] py-[128px] max-lg:mt-[40px] max-
|
|
|
390
390
|
isLogin: true
|
|
391
391
|
};
|
|
392
392
|
sessionStorage.setItem(session_key || '', JSON.stringify(userData));
|
|
393
|
-
setUser(userData);
|
|
393
|
+
setUser(userData); // <- props로 받은 setUser 호출
|
|
394
394
|
router.push(redirect);
|
|
395
395
|
}
|
|
396
396
|
else {
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import React, { FormEvent, Suspense, useCallback, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { useRouter } from 'next/navigation';
|
|
4
4
|
import { formatPhoneNumber, formatTime, getCookie, getNameValue, getPhoneValue, onlyNumberFilter } from '../../../lib';
|
|
5
|
-
import { useSetRecoilState } from 'recoil';
|
|
6
5
|
import { deleteToken, getToken } from './_api/token';
|
|
7
6
|
import { jwtDecode } from 'jwt-decode';
|
|
8
7
|
import { sendNumber } from './_api/sendNumber';
|
|
@@ -494,7 +493,7 @@ const AppSign = ({
|
|
|
494
493
|
isLogin: true
|
|
495
494
|
};
|
|
496
495
|
sessionStorage.setItem(session_key || '', JSON.stringify(userData));
|
|
497
|
-
setUser(userData);
|
|
496
|
+
setUser(userData); // <- props로 받은 setUser 호출
|
|
498
497
|
router.push(redirect);
|
|
499
498
|
} else {
|
|
500
499
|
await deleteToken();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
export interface UserInfo {
|
|
3
|
+
email: string;
|
|
4
|
+
name: string;
|
|
5
|
+
isLogin: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface Props {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
setUserInfo: (user: UserInfo) => void;
|
|
10
|
+
}
|
|
11
|
+
declare const LoginShareCheckContainer: ({ children, setUserInfo }: Props) => React.JSX.Element;
|
|
12
|
+
export default LoginShareCheckContainer;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
import React, { useEffect } from 'react';
|
|
12
|
+
const SESSION_KEY = 'login_info';
|
|
13
|
+
const LoginShareCheckContainer = ({ children, setUserInfo }) => {
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const initializeUser = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const storedUser = sessionStorage.getItem(SESSION_KEY);
|
|
17
|
+
if (storedUser) {
|
|
18
|
+
try {
|
|
19
|
+
const parsedUser = JSON.parse(storedUser);
|
|
20
|
+
setUserInfo(parsedUser);
|
|
21
|
+
if (parsedUser.isLogin) {
|
|
22
|
+
const userData = yield fetchUserData();
|
|
23
|
+
if (userData) {
|
|
24
|
+
setUserInfo(userData);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
setGuestUser();
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
console.error('Failed to parse stored user data', e);
|
|
34
|
+
sessionStorage.removeItem(SESSION_KEY);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
yield check();
|
|
38
|
+
});
|
|
39
|
+
const setGuestUser = () => {
|
|
40
|
+
const guestUser = { email: '', name: '', isLogin: false };
|
|
41
|
+
setUserInfo(guestUser);
|
|
42
|
+
sessionStorage.setItem(SESSION_KEY, JSON.stringify(guestUser));
|
|
43
|
+
};
|
|
44
|
+
const check = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
try {
|
|
46
|
+
const result = yield fetch(`https://aegis.daeryunlaw.com/api/app/auth/callback`, {
|
|
47
|
+
method: 'GET',
|
|
48
|
+
headers: { 'Content-Type': 'application/json' },
|
|
49
|
+
cache: 'no-cache',
|
|
50
|
+
credentials: 'include'
|
|
51
|
+
}).then(res => res.json());
|
|
52
|
+
if (result.result && result.jwt) {
|
|
53
|
+
const tokenCheckResult = yield fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/token`, {
|
|
54
|
+
method: 'GET',
|
|
55
|
+
headers: { 'Content-Type': 'application/json' },
|
|
56
|
+
credentials: 'include'
|
|
57
|
+
}).then(obj => obj.json());
|
|
58
|
+
if (tokenCheckResult.token) {
|
|
59
|
+
const userData = yield fetchUserData();
|
|
60
|
+
if (userData) {
|
|
61
|
+
setUserInfo(userData);
|
|
62
|
+
sessionStorage.setItem(SESSION_KEY, JSON.stringify(userData));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
setGuestUser();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const createTokenResult = yield fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/token`, {
|
|
70
|
+
body: JSON.stringify({ jwt: result.jwt }),
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: { 'Content-Type': 'application/json' },
|
|
73
|
+
credentials: 'include'
|
|
74
|
+
}).then(obj => obj.json());
|
|
75
|
+
if (createTokenResult.token) {
|
|
76
|
+
const userData = yield fetchUserData();
|
|
77
|
+
if (userData) {
|
|
78
|
+
setUserInfo(userData);
|
|
79
|
+
sessionStorage.setItem(SESSION_KEY, JSON.stringify(userData));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
setGuestUser();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
setGuestUser();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
setGuestUser();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error('Login check failed', error);
|
|
96
|
+
setGuestUser();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const fetchUserData = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
var _a, _b;
|
|
101
|
+
const result = yield fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/lawfirm/app/user`, {
|
|
102
|
+
method: 'GET',
|
|
103
|
+
headers: { 'Content-Type': 'application/json' },
|
|
104
|
+
cache: 'no-cache',
|
|
105
|
+
credentials: 'include'
|
|
106
|
+
}).then(res => res.json());
|
|
107
|
+
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.email) && ((_b = result.data) === null || _b === void 0 ? void 0 : _b.name)) {
|
|
108
|
+
return {
|
|
109
|
+
email: result.data.email,
|
|
110
|
+
name: result.data.name,
|
|
111
|
+
isLogin: true
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
});
|
|
116
|
+
initializeUser();
|
|
117
|
+
}, [setUserInfo]);
|
|
118
|
+
return <>{children}</>;
|
|
119
|
+
};
|
|
120
|
+
export default LoginShareCheckContainer;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { ReactNode, useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
export interface UserInfo {
|
|
6
|
+
email: string;
|
|
7
|
+
name: string;
|
|
8
|
+
isLogin: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const SESSION_KEY = 'login_info';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
setUserInfo: (user: UserInfo) => void; // 상태 업데이트 함수 (Recoil, Jotai 대응 가능)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const LoginShareCheckContainer = ({ children, setUserInfo }: Props) => {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const initializeUser = async () => {
|
|
21
|
+
const storedUser = sessionStorage.getItem(SESSION_KEY);
|
|
22
|
+
|
|
23
|
+
if (storedUser) {
|
|
24
|
+
try {
|
|
25
|
+
const parsedUser: UserInfo = JSON.parse(storedUser);
|
|
26
|
+
setUserInfo(parsedUser);
|
|
27
|
+
|
|
28
|
+
if (parsedUser.isLogin) {
|
|
29
|
+
const userData = await fetchUserData();
|
|
30
|
+
if (userData) {
|
|
31
|
+
setUserInfo(userData);
|
|
32
|
+
} else {
|
|
33
|
+
setGuestUser();
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error('Failed to parse stored user data', e);
|
|
39
|
+
sessionStorage.removeItem(SESSION_KEY);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
await check();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const setGuestUser = () => {
|
|
46
|
+
const guestUser: UserInfo = { email: '', name: '', isLogin: false };
|
|
47
|
+
setUserInfo(guestUser);
|
|
48
|
+
sessionStorage.setItem(SESSION_KEY, JSON.stringify(guestUser));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const check = async () => {
|
|
52
|
+
try {
|
|
53
|
+
const result = await fetch(`https://aegis.daeryunlaw.com/api/app/auth/callback`, {
|
|
54
|
+
method: 'GET',
|
|
55
|
+
headers: { 'Content-Type': 'application/json' },
|
|
56
|
+
cache: 'no-cache',
|
|
57
|
+
credentials: 'include'
|
|
58
|
+
}).then(res => res.json());
|
|
59
|
+
|
|
60
|
+
if (result.result && result.jwt) {
|
|
61
|
+
const tokenCheckResult = await fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/token`, {
|
|
62
|
+
method: 'GET',
|
|
63
|
+
headers: { 'Content-Type': 'application/json' },
|
|
64
|
+
credentials: 'include'
|
|
65
|
+
}).then(obj => obj.json());
|
|
66
|
+
|
|
67
|
+
if (tokenCheckResult.token) {
|
|
68
|
+
const userData = await fetchUserData();
|
|
69
|
+
if (userData) {
|
|
70
|
+
setUserInfo(userData);
|
|
71
|
+
sessionStorage.setItem(SESSION_KEY, JSON.stringify(userData));
|
|
72
|
+
} else {
|
|
73
|
+
setGuestUser();
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
const createTokenResult = await fetch(
|
|
77
|
+
`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/token`,
|
|
78
|
+
{
|
|
79
|
+
body: JSON.stringify({ jwt: result.jwt }),
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: { 'Content-Type': 'application/json' },
|
|
82
|
+
credentials: 'include'
|
|
83
|
+
}
|
|
84
|
+
).then(obj => obj.json());
|
|
85
|
+
|
|
86
|
+
if (createTokenResult.token) {
|
|
87
|
+
const userData = await fetchUserData();
|
|
88
|
+
if (userData) {
|
|
89
|
+
setUserInfo(userData);
|
|
90
|
+
sessionStorage.setItem(SESSION_KEY, JSON.stringify(userData));
|
|
91
|
+
} else {
|
|
92
|
+
setGuestUser();
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
setGuestUser();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
setGuestUser();
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error('Login check failed', error);
|
|
103
|
+
setGuestUser();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const fetchUserData = async (): Promise<UserInfo | null> => {
|
|
108
|
+
const result = await fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/lawfirm/app/user`, {
|
|
109
|
+
method: 'GET',
|
|
110
|
+
headers: { 'Content-Type': 'application/json' },
|
|
111
|
+
cache: 'no-cache',
|
|
112
|
+
credentials: 'include'
|
|
113
|
+
}).then(res => res.json());
|
|
114
|
+
|
|
115
|
+
if (result.data?.email && result.data?.name) {
|
|
116
|
+
return {
|
|
117
|
+
email: result.data.email,
|
|
118
|
+
name: result.data.name,
|
|
119
|
+
isLogin: true
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
initializeUser();
|
|
126
|
+
}, [setUserInfo]);
|
|
127
|
+
|
|
128
|
+
return <>{children}</>;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export default LoginShareCheckContainer;
|
|
@@ -7,19 +7,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import Fetch from '../_fetch/fetch';
|
|
10
11
|
export const logout = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const SESSION_KEY = 'loginUser';
|
|
11
13
|
try {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const res = yield Fetch('/api/lawfirm/app/auth/logout', {
|
|
15
|
+
method: 'DELETE'
|
|
16
|
+
});
|
|
17
|
+
if (res.result) {
|
|
18
|
+
const result = yield fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/token`, {
|
|
19
|
+
method: 'DELETE',
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json'
|
|
22
|
+
},
|
|
23
|
+
credentials: 'include'
|
|
24
|
+
}).then(obj => obj.json());
|
|
25
|
+
if (result.result) {
|
|
26
|
+
sessionStorage.removeItem(SESSION_KEY);
|
|
27
|
+
window.location.href = '/';
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
yield logout();
|
|
31
|
+
}
|
|
20
32
|
}
|
|
21
33
|
else {
|
|
22
|
-
|
|
34
|
+
return '';
|
|
23
35
|
}
|
|
24
36
|
return '';
|
|
25
37
|
}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
+
import Fetch from '../_fetch/fetch';
|
|
2
|
+
|
|
1
3
|
export const logout = async () => {
|
|
4
|
+
const SESSION_KEY = 'loginUser';
|
|
2
5
|
try {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const res = await Fetch('/api/lawfirm/app/auth/logout', {
|
|
7
|
+
method: 'DELETE'
|
|
8
|
+
});
|
|
9
|
+
if (res.result) {
|
|
10
|
+
const result = await fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/token`, {
|
|
11
|
+
method: 'DELETE',
|
|
12
|
+
headers: {
|
|
13
|
+
'Content-Type': 'application/json'
|
|
14
|
+
},
|
|
15
|
+
credentials: 'include'
|
|
16
|
+
}).then(obj => obj.json());
|
|
17
|
+
|
|
18
|
+
if (result.result) {
|
|
19
|
+
sessionStorage.removeItem(SESSION_KEY);
|
|
20
|
+
window.location.href = '/';
|
|
21
|
+
} else {
|
|
22
|
+
await logout();
|
|
23
|
+
}
|
|
11
24
|
} else {
|
|
12
|
-
|
|
25
|
+
return '';
|
|
13
26
|
}
|
|
14
27
|
return '';
|
|
15
28
|
} catch (e) {
|
|
@@ -5,8 +5,5 @@ type props = {
|
|
|
5
5
|
loginInfoAtom: RecoilState<ILoginInfo>;
|
|
6
6
|
};
|
|
7
7
|
export declare const useLogout: ({ sessionKey, loginInfoAtom }: props) => () => Promise<void>;
|
|
8
|
-
|
|
9
|
-
resetUser: () => void;
|
|
10
|
-
};
|
|
11
|
-
export declare const useAppLogout: ({ resetUser }: appProps) => () => Promise<void>;
|
|
8
|
+
export declare const useAppLogout: () => () => Promise<void>;
|
|
12
9
|
export {};
|
|
@@ -22,10 +22,9 @@ export const useLogout = ({ sessionKey = 'loginUser', loginInfoAtom }) => {
|
|
|
22
22
|
});
|
|
23
23
|
return logoutAction;
|
|
24
24
|
};
|
|
25
|
-
export const useAppLogout = (
|
|
25
|
+
export const useAppLogout = () => {
|
|
26
26
|
const queryClient = useQueryClient();
|
|
27
27
|
const logoutAction = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
resetUser();
|
|
29
28
|
yield logout(); // 서버 로그아웃 요청
|
|
30
29
|
queryClient.invalidateQueries({ queryKey: ['getLoginInfo'] });
|
|
31
30
|
queryClient.invalidateQueries({ queryKey: ['getLoginStatus'] });
|
|
@@ -29,11 +29,10 @@ type appProps = {
|
|
|
29
29
|
resetUser: () => void;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
export const useAppLogout = (
|
|
32
|
+
export const useAppLogout = () => {
|
|
33
33
|
const queryClient = useQueryClient();
|
|
34
34
|
|
|
35
35
|
const logoutAction = async () => {
|
|
36
|
-
resetUser();
|
|
37
36
|
await logout(); // 서버 로그아웃 요청
|
|
38
37
|
|
|
39
38
|
queryClient.invalidateQueries({ queryKey: ['getLoginInfo'] });
|