@daeryun/dr_components 0.3.50 → 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.
@@ -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 result = yield fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/logout`, {
13
- headers: {
14
- 'Content-Type': 'application/json'
15
- },
16
- credentials: 'include'
17
- }).then(obj => obj.json());
18
- if (result.result) {
19
- window.location.href = '/';
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
- yield logout();
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 result = await fetch(`${process.env.NEXT_PUBLIC_SERVICE_DOMAIN}/api/auth/logout`, {
4
- headers: {
5
- 'Content-Type': 'application/json'
6
- },
7
- credentials: 'include'
8
- }).then(obj => obj.json());
9
- if (result.result) {
10
- window.location.href = '/';
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
- await logout();
25
+ return '';
13
26
  }
14
27
  return '';
15
28
  } catch (e) {