@daeryun/dr_components 1.2.83 → 1.2.85
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,52 @@ 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, _e, _f, _g;
|
|
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
|
+
console.log('fetchUserWithIdx result:', result);
|
|
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);
|
|
59
|
+
return { isLogin: true, idx: (_d = result.data.idx) !== null && _d !== void 0 ? _d : null };
|
|
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);
|
|
62
|
+
return { isLogin: false, idx: null };
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('fetchUserWithIdx 에러:', error);
|
|
66
|
+
return { isLogin: false, idx: null };
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
// redirect URL에 uuid 추가
|
|
70
|
+
const appendUuidToRedirect = (redirect, uuid) => {
|
|
71
|
+
if (!uuid)
|
|
72
|
+
return redirect;
|
|
73
|
+
try {
|
|
74
|
+
const url = new URL(redirect, window.location.origin);
|
|
75
|
+
if (url.origin !== window.location.origin)
|
|
76
|
+
return redirect;
|
|
77
|
+
url.searchParams.set('uuid', uuid);
|
|
78
|
+
return url.pathname + url.search;
|
|
79
|
+
}
|
|
80
|
+
catch (_a) {
|
|
81
|
+
return redirect;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// GA 이벤트: 로그인 완료
|
|
85
|
+
const loginCompleteGAEvent = (userId) => {
|
|
86
|
+
gtag.event({
|
|
87
|
+
action: 'login_complete',
|
|
88
|
+
category: 'login',
|
|
89
|
+
label: `로그인 완료 - ${userId}`,
|
|
90
|
+
value: '1'
|
|
91
|
+
});
|
|
92
|
+
};
|
|
47
93
|
useEffect(() => {
|
|
48
94
|
if (!isCheckRecentLogin) {
|
|
49
95
|
return;
|
|
@@ -75,12 +121,15 @@ const LoginContainer = ({ layoutClassName = ' relative h-[100vh] max-h-[1200px]
|
|
|
75
121
|
const interval = setInterval(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
122
|
attemptCount++;
|
|
77
123
|
try {
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
124
|
+
const { isLogin, idx } = yield fetchUserWithIdx();
|
|
125
|
+
if (isLogin) {
|
|
80
126
|
const redirect = searchParam.get('redirect');
|
|
81
127
|
const normalized = redirect ? (redirect.startsWith('/') ? redirect : `/${redirect}`) : '/';
|
|
128
|
+
const finalUrl = appendUuidToRedirect(normalized, String(idx !== null && idx !== void 0 ? idx : ''));
|
|
129
|
+
// GA 이벤트
|
|
130
|
+
loginCompleteGAEvent(String(idx !== null && idx !== void 0 ? idx : ''));
|
|
82
131
|
clearInterval(interval);
|
|
83
|
-
window.location.href =
|
|
132
|
+
window.location.href = finalUrl;
|
|
84
133
|
return;
|
|
85
134
|
}
|
|
86
135
|
}
|
|
@@ -102,11 +151,14 @@ const LoginContainer = ({ layoutClassName = ' relative h-[100vh] max-h-[1200px]
|
|
|
102
151
|
}
|
|
103
152
|
}, [pathName]);
|
|
104
153
|
const handleLoginClick = (type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
154
|
+
const { isLogin, idx } = yield fetchUserWithIdx();
|
|
155
|
+
if (isLogin) {
|
|
107
156
|
const redirect = searchParam.get('redirect');
|
|
108
157
|
const normalized = redirect ? (redirect.startsWith('/') ? redirect : `/${redirect}`) : '/';
|
|
109
|
-
|
|
158
|
+
const finalUrl = appendUuidToRedirect(normalized, String(idx !== null && idx !== void 0 ? idx : ''));
|
|
159
|
+
// GA 이벤트
|
|
160
|
+
loginCompleteGAEvent(String(idx !== null && idx !== void 0 ? idx : ''));
|
|
161
|
+
window.location.href = finalUrl;
|
|
110
162
|
}
|
|
111
163
|
else {
|
|
112
164
|
const loginUrl = `https://oauth.daeryunlaw.com/login/${type}?clientKey=${clientKey}&${process.env.NODE_ENV === 'production' ? `state=${state}` : ''}`;
|
|
@@ -52,6 +52,52 @@ 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
|
+
console.log('fetchUserWithIdx result:', result);
|
|
65
|
+
|
|
66
|
+
if (result.data?.email && result.data?.name && result.data?.phone_number) {
|
|
67
|
+
console.log('로그인 성공, idx:', result.data.idx);
|
|
68
|
+
return { isLogin: true, idx: result.data.idx ?? null };
|
|
69
|
+
}
|
|
70
|
+
console.log('로그인 조건 미충족 - email:', result.data?.email, 'name:', result.data?.name, 'phone_number:', result.data?.phone_number);
|
|
71
|
+
return { isLogin: false, idx: null };
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error('fetchUserWithIdx 에러:', error);
|
|
74
|
+
return { isLogin: false, idx: null };
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// redirect URL에 uuid 추가
|
|
79
|
+
const appendUuidToRedirect = (redirect: string, uuid?: string) => {
|
|
80
|
+
if (!uuid) return redirect;
|
|
81
|
+
try {
|
|
82
|
+
const url = new URL(redirect, window.location.origin);
|
|
83
|
+
if (url.origin !== window.location.origin) return redirect;
|
|
84
|
+
url.searchParams.set('uuid', uuid);
|
|
85
|
+
return url.pathname + url.search;
|
|
86
|
+
} catch {
|
|
87
|
+
return redirect;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// GA 이벤트: 로그인 완료
|
|
92
|
+
const loginCompleteGAEvent = (userId: string) => {
|
|
93
|
+
gtag.event({
|
|
94
|
+
action: 'login_complete',
|
|
95
|
+
category: 'login',
|
|
96
|
+
label: `로그인 완료 - ${userId}`,
|
|
97
|
+
value: '1'
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
55
101
|
useEffect(() => {
|
|
56
102
|
if (!isCheckRecentLogin) {
|
|
57
103
|
return;
|
|
@@ -85,14 +131,18 @@ const LoginContainer = ({
|
|
|
85
131
|
attemptCount++;
|
|
86
132
|
|
|
87
133
|
try {
|
|
88
|
-
const
|
|
134
|
+
const { isLogin, idx } = await fetchUserWithIdx();
|
|
89
135
|
|
|
90
|
-
if (
|
|
136
|
+
if (isLogin) {
|
|
91
137
|
const redirect = searchParam.get('redirect');
|
|
92
138
|
const normalized = redirect ? (redirect.startsWith('/') ? redirect : `/${redirect}`) : '/';
|
|
139
|
+
const finalUrl = appendUuidToRedirect(normalized, String(idx ?? ''));
|
|
140
|
+
|
|
141
|
+
// GA 이벤트
|
|
142
|
+
loginCompleteGAEvent(String(idx ?? ''));
|
|
93
143
|
|
|
94
144
|
clearInterval(interval);
|
|
95
|
-
window.location.href =
|
|
145
|
+
window.location.href = finalUrl;
|
|
96
146
|
return;
|
|
97
147
|
}
|
|
98
148
|
} catch (err) {
|
|
@@ -118,11 +168,16 @@ const LoginContainer = ({
|
|
|
118
168
|
}, [pathName]);
|
|
119
169
|
|
|
120
170
|
const handleLoginClick = async (type: string) => {
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
171
|
+
const { isLogin, idx } = await fetchUserWithIdx();
|
|
172
|
+
if (isLogin) {
|
|
123
173
|
const redirect = searchParam.get('redirect');
|
|
124
174
|
const normalized = redirect ? (redirect.startsWith('/') ? redirect : `/${redirect}`) : '/';
|
|
125
|
-
|
|
175
|
+
const finalUrl = appendUuidToRedirect(normalized, String(idx ?? ''));
|
|
176
|
+
|
|
177
|
+
// GA 이벤트
|
|
178
|
+
loginCompleteGAEvent(String(idx ?? ''));
|
|
179
|
+
|
|
180
|
+
window.location.href = finalUrl;
|
|
126
181
|
} else {
|
|
127
182
|
const loginUrl = `https://oauth.daeryunlaw.com/login/${type}?clientKey=${clientKey}&${
|
|
128
183
|
process.env.NODE_ENV === 'production' ? `state=${state}` : ''
|