@daeryun/dr_components 1.2.82 → 1.2.84

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.
@@ -44,6 +44,48 @@ const LoginContainer = ({ layoutClassName = ' relative h-[100vh] max-h-[1200px]
44
44
  const result = yield fetchUserData();
45
45
  return result.isLogin;
46
46
  });
47
+ // 로그인 체크 + idx 조회
48
+ const fetchUserWithIdx = () => __awaiter(void 0, void 0, void 0, function* () {
49
+ var _a, _b, _c, _d;
50
+ try {
51
+ const result = yield fetch(`/api/lawfirm/app/user`, {
52
+ method: 'GET',
53
+ headers: { 'Content-Type': 'application/json' },
54
+ credentials: 'include'
55
+ }).then(res => res.json());
56
+ if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.email) && ((_b = result.data) === null || _b === void 0 ? void 0 : _b.name) && ((_c = result.data) === null || _c === void 0 ? void 0 : _c.phone_number)) {
57
+ return { isLogin: true, idx: (_d = result.data.idx) !== null && _d !== void 0 ? _d : null };
58
+ }
59
+ return { isLogin: false, idx: null };
60
+ }
61
+ catch (_e) {
62
+ return { isLogin: false, idx: null };
63
+ }
64
+ });
65
+ // redirect URL에 uuid 추가
66
+ const appendUuidToRedirect = (redirect, uuid) => {
67
+ if (!uuid)
68
+ return redirect;
69
+ try {
70
+ const url = new URL(redirect, window.location.origin);
71
+ if (url.origin !== window.location.origin)
72
+ return redirect;
73
+ url.searchParams.set('uuid', uuid);
74
+ return url.pathname + url.search;
75
+ }
76
+ catch (_a) {
77
+ return redirect;
78
+ }
79
+ };
80
+ // GA 이벤트: 로그인 완료
81
+ const loginCompleteGAEvent = (userId) => {
82
+ gtag.event({
83
+ action: 'login_complete',
84
+ category: 'login',
85
+ label: `로그인 완료 - ${userId}`,
86
+ value: '1'
87
+ });
88
+ };
47
89
  useEffect(() => {
48
90
  if (!isCheckRecentLogin) {
49
91
  return;
@@ -75,12 +117,15 @@ const LoginContainer = ({ layoutClassName = ' relative h-[100vh] max-h-[1200px]
75
117
  const interval = setInterval(() => __awaiter(void 0, void 0, void 0, function* () {
76
118
  attemptCount++;
77
119
  try {
78
- const result = yield userCheck();
79
- if (result) {
120
+ const { isLogin, idx } = yield fetchUserWithIdx();
121
+ if (isLogin) {
80
122
  const redirect = searchParam.get('redirect');
81
123
  const normalized = redirect ? (redirect.startsWith('/') ? redirect : `/${redirect}`) : '/';
124
+ const finalUrl = appendUuidToRedirect(normalized, String(idx !== null && idx !== void 0 ? idx : ''));
125
+ // GA 이벤트
126
+ loginCompleteGAEvent(String(idx !== null && idx !== void 0 ? idx : ''));
82
127
  clearInterval(interval);
83
- window.location.href = normalized;
128
+ window.location.href = finalUrl;
84
129
  return;
85
130
  }
86
131
  }
@@ -102,11 +147,14 @@ const LoginContainer = ({ layoutClassName = ' relative h-[100vh] max-h-[1200px]
102
147
  }
103
148
  }, [pathName]);
104
149
  const handleLoginClick = (type) => __awaiter(void 0, void 0, void 0, function* () {
105
- const result = yield userCheck();
106
- if (result) {
150
+ const { isLogin, idx } = yield fetchUserWithIdx();
151
+ if (isLogin) {
107
152
  const redirect = searchParam.get('redirect');
108
153
  const normalized = redirect ? (redirect.startsWith('/') ? redirect : `/${redirect}`) : '/';
109
- window.location.href = normalized;
154
+ const finalUrl = appendUuidToRedirect(normalized, String(idx !== null && idx !== void 0 ? idx : ''));
155
+ // GA 이벤트
156
+ loginCompleteGAEvent(String(idx !== null && idx !== void 0 ? idx : ''));
157
+ window.location.href = finalUrl;
110
158
  }
111
159
  else {
112
160
  const loginUrl = `https://oauth.daeryunlaw.com/login/${type}?clientKey=${clientKey}&${process.env.NODE_ENV === 'production' ? `state=${state}` : ''}`;
@@ -52,6 +52,47 @@ const LoginContainer = ({
52
52
  return result.isLogin;
53
53
  };
54
54
 
55
+ // 로그인 체크 + idx 조회
56
+ const fetchUserWithIdx = async (): Promise<{ isLogin: boolean; idx: number | null }> => {
57
+ try {
58
+ const result = await fetch(`/api/lawfirm/app/user`, {
59
+ method: 'GET',
60
+ headers: { 'Content-Type': 'application/json' },
61
+ credentials: 'include'
62
+ }).then(res => res.json());
63
+
64
+ if (result.data?.email && result.data?.name && result.data?.phone_number) {
65
+ return { isLogin: true, idx: result.data.idx ?? null };
66
+ }
67
+ return { isLogin: false, idx: null };
68
+ } catch {
69
+ return { isLogin: false, idx: null };
70
+ }
71
+ };
72
+
73
+ // redirect URL에 uuid 추가
74
+ const appendUuidToRedirect = (redirect: string, uuid?: string) => {
75
+ if (!uuid) return redirect;
76
+ try {
77
+ const url = new URL(redirect, window.location.origin);
78
+ if (url.origin !== window.location.origin) return redirect;
79
+ url.searchParams.set('uuid', uuid);
80
+ return url.pathname + url.search;
81
+ } catch {
82
+ return redirect;
83
+ }
84
+ };
85
+
86
+ // GA 이벤트: 로그인 완료
87
+ const loginCompleteGAEvent = (userId: string) => {
88
+ gtag.event({
89
+ action: 'login_complete',
90
+ category: 'login',
91
+ label: `로그인 완료 - ${userId}`,
92
+ value: '1'
93
+ });
94
+ };
95
+
55
96
  useEffect(() => {
56
97
  if (!isCheckRecentLogin) {
57
98
  return;
@@ -85,14 +126,18 @@ const LoginContainer = ({
85
126
  attemptCount++;
86
127
 
87
128
  try {
88
- const result = await userCheck();
129
+ const { isLogin, idx } = await fetchUserWithIdx();
89
130
 
90
- if (result) {
131
+ if (isLogin) {
91
132
  const redirect = searchParam.get('redirect');
92
133
  const normalized = redirect ? (redirect.startsWith('/') ? redirect : `/${redirect}`) : '/';
134
+ const finalUrl = appendUuidToRedirect(normalized, String(idx ?? ''));
135
+
136
+ // GA 이벤트
137
+ loginCompleteGAEvent(String(idx ?? ''));
93
138
 
94
139
  clearInterval(interval);
95
- window.location.href = normalized;
140
+ window.location.href = finalUrl;
96
141
  return;
97
142
  }
98
143
  } catch (err) {
@@ -118,11 +163,16 @@ const LoginContainer = ({
118
163
  }, [pathName]);
119
164
 
120
165
  const handleLoginClick = async (type: string) => {
121
- const result = await userCheck();
122
- if (result) {
166
+ const { isLogin, idx } = await fetchUserWithIdx();
167
+ if (isLogin) {
123
168
  const redirect = searchParam.get('redirect');
124
169
  const normalized = redirect ? (redirect.startsWith('/') ? redirect : `/${redirect}`) : '/';
125
- window.location.href = normalized;
170
+ const finalUrl = appendUuidToRedirect(normalized, String(idx ?? ''));
171
+
172
+ // GA 이벤트
173
+ loginCompleteGAEvent(String(idx ?? ''));
174
+
175
+ window.location.href = finalUrl;
126
176
  } else {
127
177
  const loginUrl = `https://oauth.daeryunlaw.com/login/${type}?clientKey=${clientKey}&${
128
178
  process.env.NODE_ENV === 'production' ? `state=${state}` : ''
package/dist/lib/utils.js CHANGED
@@ -432,14 +432,19 @@ export const setCookie = ({ key, value, days = 0.03 }) => {
432
432
  return '';
433
433
  const expires = new Date();
434
434
  expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
435
- document.cookie = `${key}=${value};expires=${expires.toUTCString()};path=/`;
435
+ document.cookie = `${key}=${encodeURIComponent(value)};expires=${expires.toUTCString()};path=/`;
436
436
  };
437
437
  export const getCookie = (key) => {
438
438
  if (typeof document === 'undefined')
439
439
  return '';
440
440
  const cookies = document.cookie.split(';');
441
441
  for (const cookie of cookies) {
442
- const [k, v] = cookie.trim().split('=');
442
+ const trimmed = cookie.trim();
443
+ const eqIndex = trimmed.indexOf('=');
444
+ if (eqIndex === -1)
445
+ continue;
446
+ const k = trimmed.slice(0, eqIndex);
447
+ const v = trimmed.slice(eqIndex + 1);
443
448
  if (k === key) {
444
449
  return v;
445
450
  }
package/dist/lib/utils.ts CHANGED
@@ -479,7 +479,7 @@ export const setCookie = ({ key, value, days = 0.03 }: { key: string; value: str
479
479
 
480
480
  const expires = new Date();
481
481
  expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
482
- document.cookie = `${key}=${value};expires=${expires.toUTCString()};path=/`;
482
+ document.cookie = `${key}=${encodeURIComponent(value)};expires=${expires.toUTCString()};path=/`;
483
483
  };
484
484
 
485
485
  export const getCookie = (key: string) => {
@@ -487,7 +487,12 @@ export const getCookie = (key: string) => {
487
487
 
488
488
  const cookies = document.cookie.split(';');
489
489
  for (const cookie of cookies) {
490
- const [k, v] = cookie.trim().split('=');
490
+ const trimmed = cookie.trim();
491
+ const eqIndex = trimmed.indexOf('=');
492
+ if (eqIndex === -1) continue;
493
+
494
+ const k = trimmed.slice(0, eqIndex);
495
+ const v = trimmed.slice(eqIndex + 1);
491
496
  if (k === key) {
492
497
  return v;
493
498
  }