@daeryun/dr_components 1.2.84 → 1.2.86

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,7 @@
1
+ /**
2
+ * 로그인 완료 후 URL에 uuid(idx)를 추가하고 GA 이벤트를 발생시키는 훅
3
+ * - 로그인된 상태이고, URL에 uuid가 없으면 uuid를 추가
4
+ * - 로그인 완료 GA 이벤트 발생
5
+ */
6
+ export declare const useLoginUuidSync: () => void;
7
+ export default useLoginUuidSync;
@@ -0,0 +1,73 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { useEffect, useRef } from 'react';
11
+ import * as gtag from '../../lib/gtag';
12
+ /**
13
+ * 로그인 완료 후 URL에 uuid(idx)를 추가하고 GA 이벤트를 발생시키는 훅
14
+ * - 로그인된 상태이고, URL에 uuid가 없으면 uuid를 추가
15
+ * - 로그인 완료 GA 이벤트 발생
16
+ */
17
+ export const useLoginUuidSync = () => {
18
+ const hasProcessed = useRef(false);
19
+ useEffect(() => {
20
+ // 이미 처리했으면 스킵
21
+ if (hasProcessed.current)
22
+ return;
23
+ const syncUuid = () => __awaiter(void 0, void 0, void 0, function* () {
24
+ var _a, _b, _c;
25
+ try {
26
+ // URL에 이미 uuid가 있으면 스킵
27
+ const urlParams = new URLSearchParams(window.location.search);
28
+ if (urlParams.has('uuid')) {
29
+ console.log('useLoginUuidSync: URL에 이미 uuid 있음');
30
+ return;
31
+ }
32
+ // 로그인 상태 및 idx 조회
33
+ const result = yield fetch(`/api/lawfirm/app/user`, {
34
+ method: 'GET',
35
+ headers: { 'Content-Type': 'application/json' },
36
+ credentials: 'include'
37
+ }).then(res => res.json());
38
+ console.log('useLoginUuidSync result:', result);
39
+ // 로그인 안 됨
40
+ 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)) {
41
+ console.log('useLoginUuidSync: 로그인 안 됨');
42
+ return;
43
+ }
44
+ const idx = result.data.idx;
45
+ if (!idx) {
46
+ console.log('useLoginUuidSync: idx 없음');
47
+ return;
48
+ }
49
+ console.log('useLoginUuidSync: 로그인 확인, idx:', idx);
50
+ // URL에 uuid 추가
51
+ const url = new URL(window.location.href);
52
+ url.searchParams.set('uuid', String(idx));
53
+ const newUrl = url.pathname + url.search;
54
+ // GA 이벤트: 로그인 완료
55
+ gtag.event({
56
+ action: 'login_complete',
57
+ category: 'login',
58
+ label: `로그인 완료 - ${idx}`,
59
+ value: '1'
60
+ });
61
+ hasProcessed.current = true;
62
+ // URL 업데이트 (히스토리에 추가하지 않고 교체)
63
+ window.history.replaceState({}, '', newUrl);
64
+ console.log('useLoginUuidSync: URL 업데이트 완료', newUrl);
65
+ }
66
+ catch (error) {
67
+ console.error('useLoginUuidSync 에러:', error);
68
+ }
69
+ });
70
+ syncUuid();
71
+ }, []);
72
+ };
73
+ export default useLoginUuidSync;
@@ -0,0 +1,75 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import * as gtag from '../../lib/gtag';
3
+
4
+ /**
5
+ * 로그인 완료 후 URL에 uuid(idx)를 추가하고 GA 이벤트를 발생시키는 훅
6
+ * - 로그인된 상태이고, URL에 uuid가 없으면 uuid를 추가
7
+ * - 로그인 완료 GA 이벤트 발생
8
+ */
9
+ export const useLoginUuidSync = () => {
10
+ const hasProcessed = useRef(false);
11
+
12
+ useEffect(() => {
13
+ // 이미 처리했으면 스킵
14
+ if (hasProcessed.current) return;
15
+
16
+ const syncUuid = async () => {
17
+ try {
18
+ // URL에 이미 uuid가 있으면 스킵
19
+ const urlParams = new URLSearchParams(window.location.search);
20
+ if (urlParams.has('uuid')) {
21
+ console.log('useLoginUuidSync: URL에 이미 uuid 있음');
22
+ return;
23
+ }
24
+
25
+ // 로그인 상태 및 idx 조회
26
+ const result = await fetch(`/api/lawfirm/app/user`, {
27
+ method: 'GET',
28
+ headers: { 'Content-Type': 'application/json' },
29
+ credentials: 'include'
30
+ }).then(res => res.json());
31
+
32
+ console.log('useLoginUuidSync result:', result);
33
+
34
+ // 로그인 안 됨
35
+ if (!result.data?.email || !result.data?.name || !result.data?.phone_number) {
36
+ console.log('useLoginUuidSync: 로그인 안 됨');
37
+ return;
38
+ }
39
+
40
+ const idx = result.data.idx;
41
+ if (!idx) {
42
+ console.log('useLoginUuidSync: idx 없음');
43
+ return;
44
+ }
45
+
46
+ console.log('useLoginUuidSync: 로그인 확인, idx:', idx);
47
+
48
+ // URL에 uuid 추가
49
+ const url = new URL(window.location.href);
50
+ url.searchParams.set('uuid', String(idx));
51
+ const newUrl = url.pathname + url.search;
52
+
53
+ // GA 이벤트: 로그인 완료
54
+ gtag.event({
55
+ action: 'login_complete',
56
+ category: 'login',
57
+ label: `로그인 완료 - ${idx}`,
58
+ value: '1'
59
+ });
60
+
61
+ hasProcessed.current = true;
62
+
63
+ // URL 업데이트 (히스토리에 추가하지 않고 교체)
64
+ window.history.replaceState({}, '', newUrl);
65
+ console.log('useLoginUuidSync: URL 업데이트 완료', newUrl);
66
+ } catch (error) {
67
+ console.error('useLoginUuidSync 에러:', error);
68
+ }
69
+ };
70
+
71
+ syncUuid();
72
+ }, []);
73
+ };
74
+
75
+ export default useLoginUuidSync;
@@ -46,19 +46,23 @@ const LoginContainer = ({ layoutClassName = ' relative h-[100vh] max-h-[1200px]
46
46
  });
47
47
  // 로그인 체크 + idx 조회
48
48
  const fetchUserWithIdx = () => __awaiter(void 0, void 0, void 0, function* () {
49
- var _a, _b, _c, _d;
49
+ var _a, _b, _c, _d, _e, _f, _g;
50
50
  try {
51
51
  const result = yield fetch(`/api/lawfirm/app/user`, {
52
52
  method: 'GET',
53
53
  headers: { 'Content-Type': 'application/json' },
54
54
  credentials: 'include'
55
55
  }).then(res => res.json());
56
+ console.log('fetchUserWithIdx result:', result);
56
57
  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)) {
58
+ console.log('로그인 성공, idx:', result.data.idx);
57
59
  return { isLogin: true, idx: (_d = result.data.idx) !== null && _d !== void 0 ? _d : null };
58
60
  }
61
+ console.log('로그인 조건 미충족 - email:', (_e = result.data) === null || _e === void 0 ? void 0 : _e.email, 'name:', (_f = result.data) === null || _f === void 0 ? void 0 : _f.name, 'phone_number:', (_g = result.data) === null || _g === void 0 ? void 0 : _g.phone_number);
59
62
  return { isLogin: false, idx: null };
60
63
  }
61
- catch (_e) {
64
+ catch (error) {
65
+ console.error('fetchUserWithIdx 에러:', error);
62
66
  return { isLogin: false, idx: null };
63
67
  }
64
68
  });
@@ -111,11 +115,13 @@ const LoginContainer = ({ layoutClassName = ' relative h-[100vh] max-h-[1200px]
111
115
  checkLogoutLogAction();
112
116
  }, []);
113
117
  useEffect(() => {
118
+ console.log('로그인 체크 useEffect 시작');
114
119
  let attemptCount = 0; // 시도 횟수
115
120
  const maxAttempts = 3; // 최대 4번
116
121
  const intervalTime = 3000; // 3초
117
122
  const interval = setInterval(() => __awaiter(void 0, void 0, void 0, function* () {
118
123
  attemptCount++;
124
+ console.log(`로그인 체크 시도 ${attemptCount}/${maxAttempts}`);
119
125
  try {
120
126
  const { isLogin, idx } = yield fetchUserWithIdx();
121
127
  if (isLogin) {
@@ -61,11 +61,16 @@ const LoginContainer = ({
61
61
  credentials: 'include'
62
62
  }).then(res => res.json());
63
63
 
64
+ console.log('fetchUserWithIdx result:', result);
65
+
64
66
  if (result.data?.email && result.data?.name && result.data?.phone_number) {
67
+ console.log('로그인 성공, idx:', result.data.idx);
65
68
  return { isLogin: true, idx: result.data.idx ?? null };
66
69
  }
70
+ console.log('로그인 조건 미충족 - email:', result.data?.email, 'name:', result.data?.name, 'phone_number:', result.data?.phone_number);
67
71
  return { isLogin: false, idx: null };
68
- } catch {
72
+ } catch (error) {
73
+ console.error('fetchUserWithIdx 에러:', error);
69
74
  return { isLogin: false, idx: null };
70
75
  }
71
76
  };
@@ -118,12 +123,14 @@ const LoginContainer = ({
118
123
  }, []);
119
124
 
120
125
  useEffect(() => {
126
+ console.log('로그인 체크 useEffect 시작');
121
127
  let attemptCount = 0; // 시도 횟수
122
128
  const maxAttempts = 3; // 최대 4번
123
129
  const intervalTime = 3000; // 3초
124
130
 
125
131
  const interval = setInterval(async () => {
126
132
  attemptCount++;
133
+ console.log(`로그인 체크 시도 ${attemptCount}/${maxAttempts}`);
127
134
 
128
135
  try {
129
136
  const { isLogin, idx } = await fetchUserWithIdx();