@payez/next-mvp 3.9.0 → 4.0.0
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/api/auth-handler.d.ts +1 -2
- package/dist/api/auth-handler.js +9 -9
- package/dist/api-handlers/account/change-password.js +110 -112
- package/dist/api-handlers/admin/analytics.d.ts +19 -20
- package/dist/api-handlers/admin/analytics.js +378 -379
- package/dist/api-handlers/admin/audit.d.ts +19 -20
- package/dist/api-handlers/admin/audit.js +213 -214
- package/dist/api-handlers/admin/index.d.ts +21 -22
- package/dist/api-handlers/admin/index.js +42 -43
- package/dist/api-handlers/admin/redis-sessions.d.ts +35 -36
- package/dist/api-handlers/admin/redis-sessions.js +203 -204
- package/dist/api-handlers/admin/sessions.d.ts +20 -21
- package/dist/api-handlers/admin/sessions.js +283 -284
- package/dist/api-handlers/admin/site-logs.d.ts +45 -46
- package/dist/api-handlers/admin/site-logs.js +317 -318
- package/dist/api-handlers/admin/stats.d.ts +20 -21
- package/dist/api-handlers/admin/stats.js +239 -240
- package/dist/api-handlers/admin/users.d.ts +19 -20
- package/dist/api-handlers/admin/users.js +221 -222
- package/dist/api-handlers/admin/vibe-data.d.ts +79 -80
- package/dist/api-handlers/admin/vibe-data.js +267 -268
- package/dist/api-handlers/auth/refresh.js +633 -635
- package/dist/api-handlers/auth/signout.js +186 -187
- package/dist/api-handlers/auth/status.js +4 -7
- package/dist/api-handlers/auth/update-session.d.ts +1 -1
- package/dist/api-handlers/auth/update-session.js +12 -14
- package/dist/api-handlers/auth/verify-code.d.ts +43 -43
- package/dist/api-handlers/auth/verify-code.js +90 -94
- package/dist/api-handlers/session/viability.js +114 -146
- package/dist/api-handlers/test/force-expire.js +59 -65
- package/dist/auth/auth-decision.js +182 -182
- package/dist/auth/better-auth.d.ts +3 -6
- package/dist/auth/better-auth.js +3 -6
- package/dist/auth/route-config.js +2 -2
- package/dist/auth/utils/token-utils.d.ts +83 -84
- package/dist/auth/utils/token-utils.js +218 -219
- package/dist/client/AuthContext.js +115 -112
- package/dist/client/better-auth-client.d.ts +1020 -961
- package/dist/client/better-auth-client.js +54 -7
- package/dist/client/fetch-with-auth.js +2 -2
- package/dist/components/SessionSync.js +121 -119
- package/dist/components/account/MobileNavDrawer.js +64 -64
- package/dist/components/account/UserAvatarMenu.js +91 -88
- package/dist/components/admin/VibeAdminLayout.js +71 -69
- package/dist/hooks/useAuth.js +9 -7
- package/dist/hooks/useAuthSettings.js +93 -93
- package/dist/hooks/useAvailableProviders.d.ts +43 -45
- package/dist/hooks/useAvailableProviders.js +112 -108
- package/dist/hooks/useSessionExpiration.d.ts +2 -3
- package/dist/hooks/useSessionExpiration.js +2 -2
- package/dist/hooks/useViabilitySession.js +3 -2
- package/dist/index.js +4 -6
- package/dist/lib/app-slug.d.ts +95 -95
- package/dist/lib/app-slug.js +172 -172
- package/dist/lib/standardized-client-api.js +10 -5
- package/dist/lib/startup-init.js +21 -25
- package/dist/lib/test-aware-get-token.js +86 -81
- package/dist/lib/token-lifecycle.d.ts +78 -52
- package/dist/lib/token-lifecycle.js +360 -398
- package/dist/pages/admin-login/page.js +73 -83
- package/dist/pages/client-admin/ClientSiteAdminPage.js +179 -177
- package/dist/pages/login/page.js +202 -211
- package/dist/pages/showcase/ShowcasePage.js +142 -140
- package/dist/pages/test-env/EmergencyLogoutPage.js +99 -98
- package/dist/pages/test-env/JwtInspectPage.js +116 -114
- package/dist/pages/test-env/RefreshTokenPage.js +4 -2
- package/dist/pages/test-env/TestEnvPage.js +51 -49
- package/dist/pages/verify-code/page.js +412 -408
- package/dist/routes/auth/logout.d.ts +31 -31
- package/dist/routes/auth/logout.js +98 -113
- package/dist/routes/auth/nextauth.d.ts +14 -11
- package/dist/routes/auth/nextauth.js +25 -57
- package/dist/routes/auth/session.js +157 -179
- package/dist/routes/auth/viability.js +190 -201
- package/dist/server/auth.d.ts +50 -0
- package/dist/server/auth.js +62 -0
- package/dist/stores/authStore.js +19 -23
- package/dist/utils/logout.js +5 -5
- package/package.json +1 -3
- package/src/api/auth-handler.ts +550 -549
- package/src/api-handlers/account/change-password.ts +5 -8
- package/src/api-handlers/admin/analytics.ts +4 -6
- package/src/api-handlers/admin/audit.ts +5 -7
- package/src/api-handlers/admin/index.ts +1 -2
- package/src/api-handlers/admin/redis-sessions.ts +6 -8
- package/src/api-handlers/admin/sessions.ts +5 -7
- package/src/api-handlers/admin/site-logs.ts +8 -10
- package/src/api-handlers/admin/stats.ts +4 -6
- package/src/api-handlers/admin/users.ts +5 -7
- package/src/api-handlers/admin/vibe-data.ts +10 -12
- package/src/api-handlers/auth/refresh.ts +5 -7
- package/src/api-handlers/auth/signout.ts +5 -6
- package/src/api-handlers/auth/status.ts +4 -7
- package/src/api-handlers/auth/update-session.ts +123 -125
- package/src/api-handlers/auth/verify-code.ts +9 -13
- package/src/api-handlers/session/viability.ts +10 -47
- package/src/api-handlers/test/force-expire.ts +4 -11
- package/src/auth/auth-decision.ts +1 -1
- package/src/auth/better-auth.ts +138 -141
- package/src/auth/route-config.ts +219 -219
- package/src/auth/utils/token-utils.ts +0 -1
- package/src/client/AuthContext.tsx +6 -2
- package/src/client/better-auth-client.ts +54 -7
- package/src/client/fetch-with-auth.ts +47 -47
- package/src/components/SessionSync.tsx +6 -5
- package/src/components/account/MobileNavDrawer.tsx +3 -3
- package/src/components/account/UserAvatarMenu.tsx +6 -3
- package/src/components/admin/VibeAdminLayout.tsx +4 -2
- package/src/config/logger.ts +1 -1
- package/src/hooks/useAuth.ts +117 -115
- package/src/hooks/useAuthSettings.ts +2 -2
- package/src/hooks/useAvailableProviders.ts +9 -5
- package/src/hooks/useSessionExpiration.ts +101 -102
- package/src/hooks/useViabilitySession.ts +336 -335
- package/src/index.ts +60 -63
- package/src/lib/api-handler.ts +0 -1
- package/src/lib/app-slug.ts +6 -6
- package/src/lib/standardized-client-api.ts +901 -895
- package/src/lib/startup-init.ts +243 -247
- package/src/lib/test-aware-get-token.ts +22 -12
- package/src/lib/token-lifecycle.ts +12 -53
- package/src/pages/admin-login/page.tsx +9 -17
- package/src/pages/client-admin/ClientSiteAdminPage.tsx +4 -2
- package/src/pages/login/page.tsx +21 -28
- package/src/pages/showcase/ShowcasePage.tsx +4 -2
- package/src/pages/test-env/EmergencyLogoutPage.tsx +7 -6
- package/src/pages/test-env/JwtInspectPage.tsx +5 -3
- package/src/pages/test-env/RefreshTokenPage.tsx +157 -155
- package/src/pages/test-env/TestEnvPage.tsx +4 -2
- package/src/pages/verify-code/page.tsx +10 -6
- package/src/routes/auth/logout.ts +7 -25
- package/src/routes/auth/nextauth.ts +45 -71
- package/src/routes/auth/session.ts +25 -50
- package/src/routes/auth/viability.ts +7 -19
- package/src/server/auth.ts +60 -0
- package/src/stores/authStore.ts +1899 -1904
- package/src/utils/logout.ts +30 -30
- package/src/auth/auth-options.ts +0 -237
- package/src/auth/callbacks/index.ts +0 -7
- package/src/auth/callbacks/jwt.ts +0 -382
- package/src/auth/callbacks/session.ts +0 -243
- package/src/auth/callbacks/signin.ts +0 -56
- package/src/auth/events/index.ts +0 -5
- package/src/auth/events/signout.ts +0 -33
- package/src/auth/providers/credentials.ts +0 -256
- package/src/auth/providers/index.ts +0 -6
- package/src/auth/providers/oauth.ts +0 -114
- package/src/lib/nextauth-secret.ts +0 -121
- package/src/types/next-auth.d.ts +0 -15
|
@@ -1,408 +1,412 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Themed 2FA Verification Page for @payez/next-mvp
|
|
4
|
-
*
|
|
5
|
-
* PLAIN STYLING, FULL FUNCTIONALITY
|
|
6
|
-
* - Clean, professional appearance
|
|
7
|
-
* - All functional patterns from website-membership
|
|
8
|
-
* - Themeable via ThemeProvider
|
|
9
|
-
*
|
|
10
|
-
* DEPENDENCIES: Only React, Next.js, next-auth, and Tailwind CSS
|
|
11
|
-
* NO shadcn/ui or other UI library required!
|
|
12
|
-
*
|
|
13
|
-
* FEATURES:
|
|
14
|
-
* ✅ Progressive disclosure: method selection → code input
|
|
15
|
-
* ✅ Method locking after selection (prevents accidental multi-send)
|
|
16
|
-
* ✅ Masked contact info display (informational only)
|
|
17
|
-
* ✅ Auto-submit when code reaches 6 digits
|
|
18
|
-
* ✅ Cooldown timers (30s) on resend buttons
|
|
19
|
-
* ✅ Stale session detection (401 → redirect to login)
|
|
20
|
-
* ✅ JWT-specific error detection and messaging
|
|
21
|
-
* ✅ Session viability polling (every 30s) to detect expiration early
|
|
22
|
-
* ✅ Duplicate submission prevention
|
|
23
|
-
* ✅ Success/error states with atomic management
|
|
24
|
-
* ✅ "Change method" action
|
|
25
|
-
* ✅ Session cleanup on success/expiry
|
|
26
|
-
*
|
|
27
|
-
* USAGE:
|
|
28
|
-
* 1. Import from @payez/next-mvp/pages/verify-code
|
|
29
|
-
* 2. Wrap your app with ThemeProvider to customize branding
|
|
30
|
-
*/
|
|
31
|
-
'use client';
|
|
32
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
-
exports.default = VerifyCodePage;
|
|
34
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
35
|
-
const react_1 = require("react");
|
|
36
|
-
const navigation_1 = require("next/navigation");
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const useTheme_1 = require("../../theme/useTheme");
|
|
40
|
-
/**
|
|
41
|
-
* Session storage key to track that user intentionally navigated to verify-code.
|
|
42
|
-
* Prevents auto-redirect back to dashboard when session refreshes in background.
|
|
43
|
-
*/
|
|
44
|
-
const VERIFY_IN_PROGRESS_KEY = 'idealvibe_2fa_verify_in_progress';
|
|
45
|
-
function VerifyCodeForm() {
|
|
46
|
-
const router = (0, navigation_1.useRouter)();
|
|
47
|
-
const searchParams = (0, navigation_1.useSearchParams)();
|
|
48
|
-
const callbackUrl = searchParams?.get('callbackUrl') || '/dashboard';
|
|
49
|
-
const { data:
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
const [
|
|
56
|
-
const [
|
|
57
|
-
//
|
|
58
|
-
const [
|
|
59
|
-
const [
|
|
60
|
-
const [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const [
|
|
64
|
-
const [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
lastSubmittedCode.current
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
//
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (
|
|
304
|
-
try
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
//
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
//
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
background: 'hsl(var(--card))',
|
|
383
|
-
borderColor: 'hsl(var(--border))',
|
|
384
|
-
color: 'hsl(var(--foreground))'
|
|
385
|
-
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: "text-left", children: [(0, jsx_runtime_1.jsx)("p", { className: "font-medium", style: { color: 'hsl(var(--foreground))' }, children: "
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
function
|
|
407
|
-
|
|
408
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Themed 2FA Verification Page for @payez/next-mvp
|
|
4
|
+
*
|
|
5
|
+
* PLAIN STYLING, FULL FUNCTIONALITY
|
|
6
|
+
* - Clean, professional appearance
|
|
7
|
+
* - All functional patterns from website-membership
|
|
8
|
+
* - Themeable via ThemeProvider
|
|
9
|
+
*
|
|
10
|
+
* DEPENDENCIES: Only React, Next.js, next-auth, and Tailwind CSS
|
|
11
|
+
* NO shadcn/ui or other UI library required!
|
|
12
|
+
*
|
|
13
|
+
* FEATURES:
|
|
14
|
+
* ✅ Progressive disclosure: method selection → code input
|
|
15
|
+
* ✅ Method locking after selection (prevents accidental multi-send)
|
|
16
|
+
* ✅ Masked contact info display (informational only)
|
|
17
|
+
* ✅ Auto-submit when code reaches 6 digits
|
|
18
|
+
* ✅ Cooldown timers (30s) on resend buttons
|
|
19
|
+
* ✅ Stale session detection (401 → redirect to login)
|
|
20
|
+
* ✅ JWT-specific error detection and messaging
|
|
21
|
+
* ✅ Session viability polling (every 30s) to detect expiration early
|
|
22
|
+
* ✅ Duplicate submission prevention
|
|
23
|
+
* ✅ Success/error states with atomic management
|
|
24
|
+
* ✅ "Change method" action
|
|
25
|
+
* ✅ Session cleanup on success/expiry
|
|
26
|
+
*
|
|
27
|
+
* USAGE:
|
|
28
|
+
* 1. Import from @payez/next-mvp/pages/verify-code
|
|
29
|
+
* 2. Wrap your app with ThemeProvider to customize branding
|
|
30
|
+
*/
|
|
31
|
+
'use client';
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.default = VerifyCodePage;
|
|
34
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
35
|
+
const react_1 = require("react");
|
|
36
|
+
const navigation_1 = require("next/navigation");
|
|
37
|
+
const better_auth_client_1 = require("../../client/better-auth-client");
|
|
38
|
+
const react_2 = require("react");
|
|
39
|
+
const useTheme_1 = require("../../theme/useTheme");
|
|
40
|
+
/**
|
|
41
|
+
* Session storage key to track that user intentionally navigated to verify-code.
|
|
42
|
+
* Prevents auto-redirect back to dashboard when session refreshes in background.
|
|
43
|
+
*/
|
|
44
|
+
const VERIFY_IN_PROGRESS_KEY = 'idealvibe_2fa_verify_in_progress';
|
|
45
|
+
function VerifyCodeForm() {
|
|
46
|
+
const router = (0, navigation_1.useRouter)();
|
|
47
|
+
const searchParams = (0, navigation_1.useSearchParams)();
|
|
48
|
+
const callbackUrl = searchParams?.get('callbackUrl') || '/dashboard';
|
|
49
|
+
const { data: sessionData, isPending } = better_auth_client_1.authClient.useSession();
|
|
50
|
+
const session = sessionData;
|
|
51
|
+
const status = isPending ? 'loading' : session ? 'authenticated' : 'unauthenticated';
|
|
52
|
+
// TODO: Better Auth session refresh
|
|
53
|
+
const updateSession = async () => { return session; };
|
|
54
|
+
const colors = (0, useTheme_1.useColors)();
|
|
55
|
+
const [method, setMethod] = (0, react_1.useState)(null);
|
|
56
|
+
const [methodLocked, setMethodLocked] = (0, react_1.useState)(false);
|
|
57
|
+
// Form state
|
|
58
|
+
const [code, setCode] = (0, react_1.useState)('');
|
|
59
|
+
const [maskedInfo, setMaskedInfo] = (0, react_1.useState)(null);
|
|
60
|
+
const [loadingMasked, setLoadingMasked] = (0, react_1.useState)(true);
|
|
61
|
+
// Atomic state - only one active at a time
|
|
62
|
+
const [sending, setSending] = (0, react_1.useState)(false);
|
|
63
|
+
const [verifying, setVerifying] = (0, react_1.useState)(false);
|
|
64
|
+
const [success, setSuccess] = (0, react_1.useState)(false);
|
|
65
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
66
|
+
// Cooldown timers
|
|
67
|
+
const [emailCooldown, setEmailCooldown] = (0, react_1.useState)(0);
|
|
68
|
+
const [smsCooldown, setSmsCooldown] = (0, react_1.useState)(0);
|
|
69
|
+
// Toast notifications
|
|
70
|
+
const [toast, setToast] = (0, react_1.useState)(null);
|
|
71
|
+
// Refs
|
|
72
|
+
const codeInputRef = (0, react_1.useRef)(null);
|
|
73
|
+
const lastSubmittedCode = (0, react_1.useRef)('');
|
|
74
|
+
// Track that user is intentionally on this page
|
|
75
|
+
const [verifyInProgress, setVerifyInProgress] = (0, react_1.useState)(false);
|
|
76
|
+
// ==========================================================================
|
|
77
|
+
// CRITICAL FIX: Mark that user is intentionally on verify page
|
|
78
|
+
// This prevents auto-redirect when background token refresh updates session
|
|
79
|
+
// ==========================================================================
|
|
80
|
+
(0, react_1.useEffect)(() => {
|
|
81
|
+
// On mount, mark that verification is in progress
|
|
82
|
+
if (typeof window !== 'undefined') {
|
|
83
|
+
const wasInProgress = sessionStorage.getItem(VERIFY_IN_PROGRESS_KEY) === 'true';
|
|
84
|
+
if (!wasInProgress) {
|
|
85
|
+
console.log('[2FA] User navigated to verify-code page, marking verify in progress');
|
|
86
|
+
sessionStorage.setItem(VERIFY_IN_PROGRESS_KEY, 'true');
|
|
87
|
+
}
|
|
88
|
+
setVerifyInProgress(true);
|
|
89
|
+
}
|
|
90
|
+
}, []);
|
|
91
|
+
// Auto-dismiss toast
|
|
92
|
+
(0, react_1.useEffect)(() => {
|
|
93
|
+
if (toast) {
|
|
94
|
+
const timer = setTimeout(() => setToast(null), 2500);
|
|
95
|
+
return () => clearTimeout(timer);
|
|
96
|
+
}
|
|
97
|
+
}, [toast]);
|
|
98
|
+
// Cooldown countdown
|
|
99
|
+
(0, react_1.useEffect)(() => {
|
|
100
|
+
if (emailCooldown > 0) {
|
|
101
|
+
const timer = setTimeout(() => setEmailCooldown(emailCooldown - 1), 1000);
|
|
102
|
+
return () => clearTimeout(timer);
|
|
103
|
+
}
|
|
104
|
+
}, [emailCooldown]);
|
|
105
|
+
(0, react_1.useEffect)(() => {
|
|
106
|
+
if (smsCooldown > 0) {
|
|
107
|
+
const timer = setTimeout(() => setSmsCooldown(smsCooldown - 1), 1000);
|
|
108
|
+
return () => clearTimeout(timer);
|
|
109
|
+
}
|
|
110
|
+
}, [smsCooldown]);
|
|
111
|
+
// Fetch masked info on mount
|
|
112
|
+
(0, react_1.useEffect)(() => {
|
|
113
|
+
const fetchMaskedInfo = async () => {
|
|
114
|
+
// BUGFIX: Always set loadingMasked=false, even if not authenticated
|
|
115
|
+
// Otherwise page stays stuck in loading spinner
|
|
116
|
+
if (status !== 'authenticated' || !session) {
|
|
117
|
+
setLoadingMasked(false);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const res = await fetch('/api/account/masked-info', {
|
|
122
|
+
method: 'POST',
|
|
123
|
+
credentials: 'include',
|
|
124
|
+
});
|
|
125
|
+
if (res.status === 401) {
|
|
126
|
+
// Session expired - redirect to login
|
|
127
|
+
setError('Your session has expired. Redirecting to login...');
|
|
128
|
+
setTimeout(async () => {
|
|
129
|
+
await better_auth_client_1.authClient.signOut();
|
|
130
|
+
const safeCallback = callbackUrl.startsWith('/account-auth/') ? '/dashboard' : callbackUrl;
|
|
131
|
+
router.push(`/account-auth/login?callbackUrl=${encodeURIComponent(safeCallback)}`);
|
|
132
|
+
}, 1200);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (!res.ok) {
|
|
136
|
+
throw new Error('Failed to load contact information');
|
|
137
|
+
}
|
|
138
|
+
const data = await res.json();
|
|
139
|
+
setMaskedInfo(data);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
console.error('[2FA] Error fetching masked info:', err);
|
|
143
|
+
setError('Could not load your contact information. Please try again.');
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
setLoadingMasked(false);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
fetchMaskedInfo();
|
|
150
|
+
}, [status, session, callbackUrl, router]);
|
|
151
|
+
// Auto-submit when code is 6 digits
|
|
152
|
+
(0, react_1.useEffect)(() => {
|
|
153
|
+
if (code.length === 6 && method && !verifying) {
|
|
154
|
+
handleVerifyCode();
|
|
155
|
+
}
|
|
156
|
+
}, [code, method, verifying]);
|
|
157
|
+
// ==========================================================================
|
|
158
|
+
// Session viability check - detect expiration early and warn user
|
|
159
|
+
// ==========================================================================
|
|
160
|
+
(0, react_1.useEffect)(() => {
|
|
161
|
+
if (status !== 'authenticated')
|
|
162
|
+
return;
|
|
163
|
+
// Check session viability every 30 seconds
|
|
164
|
+
const checkSession = async () => {
|
|
165
|
+
try {
|
|
166
|
+
const res = await fetch('/api/session/viability', {
|
|
167
|
+
credentials: 'include',
|
|
168
|
+
});
|
|
169
|
+
if (res.status === 401) {
|
|
170
|
+
const data = await res.json().catch(() => ({}));
|
|
171
|
+
// Session is no longer valid - warn user and redirect
|
|
172
|
+
if (data.valid === false || data.mfaExpired === true) {
|
|
173
|
+
setError('Your session has expired. Redirecting to login...');
|
|
174
|
+
setTimeout(async () => {
|
|
175
|
+
await better_auth_client_1.authClient.signOut();
|
|
176
|
+
if (typeof window !== 'undefined') {
|
|
177
|
+
sessionStorage.removeItem(VERIFY_IN_PROGRESS_KEY);
|
|
178
|
+
}
|
|
179
|
+
router.push(`/account-auth/login?error=SessionExpired`);
|
|
180
|
+
}, 2000);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
// Silent fail - let the next actual API call handle the error
|
|
186
|
+
console.log('[2FA] Session viability check failed:', err);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
// Initial check after 5 seconds, then every 30 seconds
|
|
190
|
+
const initialTimeout = setTimeout(checkSession, 5000);
|
|
191
|
+
const interval = setInterval(checkSession, 30000);
|
|
192
|
+
return () => {
|
|
193
|
+
clearTimeout(initialTimeout);
|
|
194
|
+
clearInterval(interval);
|
|
195
|
+
};
|
|
196
|
+
}, [status, router]);
|
|
197
|
+
const handleSendCode = async (selectedMethod) => {
|
|
198
|
+
setSending(true);
|
|
199
|
+
setError(null);
|
|
200
|
+
try {
|
|
201
|
+
const res = await fetch('/api/account/send-code', {
|
|
202
|
+
method: 'POST',
|
|
203
|
+
headers: { 'Content-Type': 'application/json' },
|
|
204
|
+
body: JSON.stringify({ method: selectedMethod }),
|
|
205
|
+
credentials: 'include',
|
|
206
|
+
});
|
|
207
|
+
if (res.status === 401) {
|
|
208
|
+
const errorData = await res.json().catch(() => ({}));
|
|
209
|
+
const isJwtExpired = errorData?.error?.includes('JWT') || errorData?.message?.includes('JWT') || errorData?.error?.includes('expired');
|
|
210
|
+
setError(isJwtExpired
|
|
211
|
+
? 'Your 2FA session has expired. Please sign in again.'
|
|
212
|
+
: 'Your session has expired. Redirecting to login...');
|
|
213
|
+
setTimeout(async () => {
|
|
214
|
+
await better_auth_client_1.authClient.signOut();
|
|
215
|
+
if (typeof window !== 'undefined') {
|
|
216
|
+
sessionStorage.removeItem(VERIFY_IN_PROGRESS_KEY);
|
|
217
|
+
}
|
|
218
|
+
const safeCallback = callbackUrl.startsWith('/account-auth/') ? '/dashboard' : callbackUrl;
|
|
219
|
+
const errorParam = isJwtExpired ? '&error=SessionExpired' : '';
|
|
220
|
+
router.push(`/account-auth/login?callbackUrl=${encodeURIComponent(safeCallback)}${errorParam}`);
|
|
221
|
+
}, 1500);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (!res.ok) {
|
|
225
|
+
const data = await res.json();
|
|
226
|
+
throw new Error(data.message || data.error || 'Failed to send code');
|
|
227
|
+
}
|
|
228
|
+
// Lock method and set cooldown
|
|
229
|
+
setMethod(selectedMethod);
|
|
230
|
+
setMethodLocked(true);
|
|
231
|
+
if (selectedMethod === 'email') {
|
|
232
|
+
setEmailCooldown(30);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
setSmsCooldown(30);
|
|
236
|
+
}
|
|
237
|
+
setToast({
|
|
238
|
+
type: 'success',
|
|
239
|
+
message: `Verification code sent to your ${selectedMethod === 'email' ? 'email' : 'phone'}`,
|
|
240
|
+
});
|
|
241
|
+
// Focus code input
|
|
242
|
+
setTimeout(() => codeInputRef.current?.focus(), 100);
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
setError(err instanceof Error ? err.message : 'Failed to send verification code');
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
setSending(false);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
const handleVerifyCode = async () => {
|
|
252
|
+
if (!code || !method || code.length !== 6) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
// Prevent duplicate submissions
|
|
256
|
+
if (lastSubmittedCode.current === code) {
|
|
257
|
+
console.log('[2FA] Duplicate submission prevented');
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
lastSubmittedCode.current = code;
|
|
261
|
+
setVerifying(true);
|
|
262
|
+
setError(null);
|
|
263
|
+
try {
|
|
264
|
+
const endpoint = method === 'sms' ? '/api/account/verify-sms' : '/api/account/verify-email';
|
|
265
|
+
const res = await fetch(endpoint, {
|
|
266
|
+
method: 'POST',
|
|
267
|
+
headers: { 'Content-Type': 'application/json' },
|
|
268
|
+
body: JSON.stringify({ verificationCode: code }),
|
|
269
|
+
credentials: 'include',
|
|
270
|
+
});
|
|
271
|
+
if (res.status === 401) {
|
|
272
|
+
const errorData = await res.json().catch(() => ({}));
|
|
273
|
+
const isJwtExpired = errorData?.error?.includes('JWT') || errorData?.message?.includes('JWT') || errorData?.error?.includes('expired');
|
|
274
|
+
setError(isJwtExpired
|
|
275
|
+
? 'Your 2FA session has expired. Please sign in again.'
|
|
276
|
+
: 'Your session has expired. Redirecting to login...');
|
|
277
|
+
setTimeout(async () => {
|
|
278
|
+
await better_auth_client_1.authClient.signOut();
|
|
279
|
+
if (typeof window !== 'undefined') {
|
|
280
|
+
sessionStorage.removeItem(VERIFY_IN_PROGRESS_KEY);
|
|
281
|
+
}
|
|
282
|
+
const safeCallback = callbackUrl.startsWith('/account-auth/') ? '/dashboard' : callbackUrl;
|
|
283
|
+
const errorParam = isJwtExpired ? '&error=SessionExpired' : '';
|
|
284
|
+
router.push(`/account-auth/login?callbackUrl=${encodeURIComponent(safeCallback)}${errorParam}`);
|
|
285
|
+
}, 1500);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (!res.ok) {
|
|
289
|
+
const data = await res.json();
|
|
290
|
+
throw new Error(data.error || data.message || 'Verification failed');
|
|
291
|
+
}
|
|
292
|
+
const result = await res.json();
|
|
293
|
+
// Normalize response: support both enveloped and unwrapped payloads
|
|
294
|
+
const payload = (result && typeof result === 'object' && 'data' in result)
|
|
295
|
+
? result.data
|
|
296
|
+
: result;
|
|
297
|
+
// Check if verification was successful
|
|
298
|
+
const verified = payload?.verificationSuccessful === true ||
|
|
299
|
+
payload?.twoFactorSessionVerified === true ||
|
|
300
|
+
payload?.success === true ||
|
|
301
|
+
// Accept token-based success (unwrapped raw tokens from backend)
|
|
302
|
+
(!!payload?.access_token && !!payload?.refresh_token);
|
|
303
|
+
if (!verified) {
|
|
304
|
+
throw new Error('Verification failed. Please try again.');
|
|
305
|
+
}
|
|
306
|
+
// CRITICAL: If tokens are included (unwrapped response), persist them in server session
|
|
307
|
+
if (payload?.access_token && payload?.refresh_token) {
|
|
308
|
+
try {
|
|
309
|
+
console.log('[2FA] Updating session with new MFA tokens...');
|
|
310
|
+
const updateRes = await fetch('/api/auth/update-session', {
|
|
311
|
+
method: 'POST',
|
|
312
|
+
headers: { 'Content-Type': 'application/json' },
|
|
313
|
+
credentials: 'include',
|
|
314
|
+
body: JSON.stringify({
|
|
315
|
+
access_token: payload.access_token,
|
|
316
|
+
refresh_token: payload.refresh_token
|
|
317
|
+
})
|
|
318
|
+
});
|
|
319
|
+
if (!updateRes.ok) {
|
|
320
|
+
console.warn('[2FA] update-session returned non-OK status:', updateRes.status);
|
|
321
|
+
const errorData = await updateRes.json();
|
|
322
|
+
console.warn('[2FA] update-session error:', errorData);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
console.log('[2FA] Session updated successfully with MFA tokens');
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
catch (e) {
|
|
329
|
+
console.warn('[2FA] Failed to call update-session:', e);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
// Show success state
|
|
333
|
+
setSuccess(true);
|
|
334
|
+
setError(null);
|
|
335
|
+
// CRITICAL: Force NextAuth to refetch session from server
|
|
336
|
+
// This ensures useSession() gets the updated twoFactorComplete: true
|
|
337
|
+
console.log('[2FA] Forcing session refresh after verification...');
|
|
338
|
+
try {
|
|
339
|
+
await updateSession(); // This triggers /api/auth/session and updates useSession() state
|
|
340
|
+
console.log('[2FA] Session refresh completed');
|
|
341
|
+
}
|
|
342
|
+
catch (e) {
|
|
343
|
+
console.warn('[2FA] updateSession failed:', e);
|
|
344
|
+
}
|
|
345
|
+
// Clear verify-in-progress flag before redirect
|
|
346
|
+
if (typeof window !== 'undefined') {
|
|
347
|
+
sessionStorage.removeItem(VERIFY_IN_PROGRESS_KEY);
|
|
348
|
+
}
|
|
349
|
+
// Redirect after showing success state
|
|
350
|
+
setTimeout(() => {
|
|
351
|
+
window.location.href = callbackUrl;
|
|
352
|
+
}, 1500);
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
setError(err instanceof Error ? err.message : 'Failed to verify code');
|
|
356
|
+
lastSubmittedCode.current = ''; // Allow retry
|
|
357
|
+
}
|
|
358
|
+
finally {
|
|
359
|
+
setVerifying(false);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
const handleResetMethod = () => {
|
|
363
|
+
setMethod(null);
|
|
364
|
+
setMethodLocked(false);
|
|
365
|
+
setCode('');
|
|
366
|
+
setError(null);
|
|
367
|
+
setEmailCooldown(0);
|
|
368
|
+
setSmsCooldown(0);
|
|
369
|
+
lastSubmittedCode.current = '';
|
|
370
|
+
};
|
|
371
|
+
const handleCodeChange = (e) => {
|
|
372
|
+
const value = e.target.value.replace(/[^0-9]/g, '').slice(0, 6);
|
|
373
|
+
setCode(value);
|
|
374
|
+
};
|
|
375
|
+
// Loading state
|
|
376
|
+
if (status === 'loading' || loadingMasked) {
|
|
377
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col items-center justify-center py-8", style: { background: 'hsl(var(--background))' }, children: [(0, jsx_runtime_1.jsxs)("svg", { className: "animate-spin h-10 w-10", style: { color: 'hsl(var(--primary))' }, viewBox: "0 0 24 24", fill: "none", children: [(0, jsx_runtime_1.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), (0, jsx_runtime_1.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z" })] }), (0, jsx_runtime_1.jsx)("p", { className: "mt-4 text-sm", style: { color: 'hsl(var(--muted-foreground))' }, children: "Loading..." })] }));
|
|
378
|
+
}
|
|
379
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-center px-4 py-8", style: { background: 'hsl(var(--background))' }, children: (0, jsx_runtime_1.jsxs)("div", { className: "max-w-md w-full", children: [toast && ((0, jsx_runtime_1.jsx)("div", { className: `fixed top-4 right-4 p-4 rounded border transition-all duration-300 ${toast.type === 'success' ? 'bg-green-50 text-green-800 border-green-200' : 'bg-red-50 text-red-800 border-red-200'}`, children: toast.message })), (0, jsx_runtime_1.jsxs)("div", { className: "rounded-2xl border p-8", style: { background: 'hsl(var(--card))', borderColor: 'hsl(var(--border))' }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-6", children: [(0, jsx_runtime_1.jsx)("h1", { className: "text-2xl font-semibold mb-2", style: { color: 'hsl(var(--foreground))' }, children: "Verify Your Identity" }), (0, jsx_runtime_1.jsx)("p", { className: "text-sm", style: { color: 'hsl(var(--muted-foreground))' }, children: "Choose how you'd like to receive your verification code" })] }), maskedInfo && ((0, jsx_runtime_1.jsxs)("div", { className: "mb-6 p-3 rounded border text-sm", style: { background: 'hsl(var(--muted) / 0.1)', borderColor: 'hsl(var(--border))', color: 'hsl(var(--foreground))' }, children: [maskedInfo.masked_email && ((0, jsx_runtime_1.jsxs)("div", { className: "mb-1", children: ["Email: ", (0, jsx_runtime_1.jsx)("span", { className: "font-mono", children: maskedInfo.masked_email })] })), maskedInfo.masked_phone_number && ((0, jsx_runtime_1.jsxs)("div", { children: ["Phone: ", (0, jsx_runtime_1.jsx)("span", { className: "font-mono", children: maskedInfo.masked_phone_number })] }))] })), !method ? (
|
|
380
|
+
/* Method Selection */
|
|
381
|
+
(0, jsx_runtime_1.jsxs)("div", { className: "space-y-3", children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", onClick: () => handleSendCode('email'), disabled: sending || !maskedInfo?.masked_email, className: "w-full flex items-center justify-between p-3 border rounded disabled:opacity-50 disabled:cursor-not-allowed transition-colors", style: {
|
|
382
|
+
background: 'hsl(var(--card))',
|
|
383
|
+
borderColor: 'hsl(var(--border))',
|
|
384
|
+
color: 'hsl(var(--foreground))'
|
|
385
|
+
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: "text-left", children: [(0, jsx_runtime_1.jsx)("p", { className: "font-medium", style: { color: 'hsl(var(--foreground))' }, children: "Email" }), (0, jsx_runtime_1.jsx)("p", { className: "text-sm", style: { color: 'hsl(var(--muted-foreground))' }, children: maskedInfo?.masked_email || 'Not available' })] }), (0, jsx_runtime_1.jsx)("span", { style: { color: 'hsl(var(--muted-foreground))' }, children: "\u2192" })] }), (0, jsx_runtime_1.jsxs)("button", { type: "button", onClick: () => handleSendCode('sms'), disabled: sending || !maskedInfo?.masked_phone_number, className: "w-full flex items-center justify-between p-3 border rounded disabled:opacity-50 disabled:cursor-not-allowed transition-colors", style: {
|
|
386
|
+
background: 'hsl(var(--card))',
|
|
387
|
+
borderColor: 'hsl(var(--border))',
|
|
388
|
+
color: 'hsl(var(--foreground))'
|
|
389
|
+
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: "text-left", children: [(0, jsx_runtime_1.jsx)("p", { className: "font-medium", style: { color: 'hsl(var(--foreground))' }, children: "SMS" }), (0, jsx_runtime_1.jsx)("p", { className: "text-sm", style: { color: 'hsl(var(--muted-foreground))' }, children: maskedInfo?.masked_phone_number || 'Not available' })] }), (0, jsx_runtime_1.jsx)("span", { style: { color: 'hsl(var(--muted-foreground))' }, children: "\u2192" })] })] })) : (
|
|
390
|
+
/* Code Input */
|
|
391
|
+
(0, jsx_runtime_1.jsxs)("div", { className: "space-y-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between p-3 rounded border", style: { background: 'hsl(var(--muted) / 0.1)', borderColor: 'hsl(var(--border))' }, children: [(0, jsx_runtime_1.jsxs)("span", { className: "text-sm", style: { color: 'hsl(var(--foreground))' }, children: ["Code sent to your ", method === 'email' ? 'email' : 'phone'] }), (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: handleResetMethod, className: "text-sm hover:underline font-medium", style: { color: 'hsl(var(--primary))' }, children: "Change method" })] }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: "code", className: "block text-sm font-medium mb-2", style: { color: 'hsl(var(--foreground))' }, children: "Verification Code" }), (0, jsx_runtime_1.jsx)("input", { ref: codeInputRef, id: "code", type: "text", inputMode: "numeric", pattern: "[0-9]*", maxLength: 6, value: code, onChange: handleCodeChange, className: "w-full px-4 py-3 text-center text-2xl font-mono border rounded focus:ring-2 tracking-widest", style: {
|
|
392
|
+
background: 'hsl(var(--input))',
|
|
393
|
+
borderColor: 'hsl(var(--border))',
|
|
394
|
+
color: 'hsl(var(--foreground))',
|
|
395
|
+
caretColor: 'hsl(var(--foreground))'
|
|
396
|
+
}, placeholder: "000000", disabled: verifying || success, autoComplete: "one-time-code", autoFocus: true }), (0, jsx_runtime_1.jsx)("p", { className: "mt-2 text-sm text-center", style: { color: 'hsl(var(--muted-foreground))' }, children: "Enter the 6-digit code" })] }), (0, jsx_runtime_1.jsx)("div", { className: "min-h-[3.5rem] flex items-center", children: verifying ? ((0, jsx_runtime_1.jsxs)("div", { className: "w-full flex items-start space-x-2 p-3 rounded border", style: { background: 'hsl(var(--muted) / 0.1)', borderColor: 'hsl(var(--border))' }, children: [(0, jsx_runtime_1.jsxs)("svg", { className: "animate-spin w-4 h-4 mt-0.5", style: { color: 'hsl(var(--primary))' }, fill: "none", viewBox: "0 0 24 24", children: [(0, jsx_runtime_1.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), (0, jsx_runtime_1.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), (0, jsx_runtime_1.jsx)("span", { className: "text-sm", style: { color: 'hsl(var(--foreground))' }, children: "Verifying code..." })] })) : error ? ((0, jsx_runtime_1.jsxs)("div", { className: "w-full flex items-start space-x-2 p-3 rounded bg-red-50 border border-red-200", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-red-700 text-sm font-medium", children: "\u2717" }), (0, jsx_runtime_1.jsx)("span", { className: "text-red-700 text-sm", children: error })] })) : success ? ((0, jsx_runtime_1.jsxs)("div", { className: "w-full flex items-start space-x-2 p-2.5 rounded bg-green-50 border border-green-200", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-green-700 text-xs font-medium", children: "\u2713" }), (0, jsx_runtime_1.jsx)("span", { className: "text-green-700 text-xs", children: "Verification successful! Redirecting..." })] })) : null }), methodLocked && ((0, jsx_runtime_1.jsx)("button", { type: "button", onClick: () => handleSendCode(method), disabled: sending || (method === 'email' ? emailCooldown > 0 : smsCooldown > 0), className: "w-full text-sm hover:underline font-medium disabled:no-underline disabled:cursor-not-allowed disabled:opacity-50", style: { color: 'hsl(var(--primary))' }, children: sending
|
|
397
|
+
? 'Sending...'
|
|
398
|
+
: method === 'email'
|
|
399
|
+
? emailCooldown > 0
|
|
400
|
+
? `Resend code in ${emailCooldown}s`
|
|
401
|
+
: 'Resend code'
|
|
402
|
+
: smsCooldown > 0
|
|
403
|
+
? `Resend code in ${smsCooldown}s`
|
|
404
|
+
: 'Resend code' }))] }))] }), (0, jsx_runtime_1.jsx)("p", { className: "mt-4 text-center text-sm", style: { color: 'hsl(var(--muted-foreground))' }, children: (0, jsx_runtime_1.jsx)("a", { href: "/account-auth/login", className: "hover:underline font-medium", style: { color: 'hsl(var(--primary))' }, children: "Back to login" }) })] }) }));
|
|
405
|
+
}
|
|
406
|
+
function VerifyCodePageFallback() {
|
|
407
|
+
const colors = (0, useTheme_1.useColors)();
|
|
408
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-center py-8", style: { background: 'hsl(var(--background))' }, children: (0, jsx_runtime_1.jsxs)("div", { className: "text-center", children: [(0, jsx_runtime_1.jsxs)("svg", { className: "animate-spin h-10 w-10 mx-auto", style: { color: 'hsl(var(--primary))' }, xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [(0, jsx_runtime_1.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), (0, jsx_runtime_1.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), (0, jsx_runtime_1.jsx)("p", { className: "mt-4", style: { color: 'hsl(var(--muted-foreground))' }, children: "Loading..." })] }) }));
|
|
409
|
+
}
|
|
410
|
+
function VerifyCodePage() {
|
|
411
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Suspense, { fallback: (0, jsx_runtime_1.jsx)(VerifyCodePageFallback, {}), children: (0, jsx_runtime_1.jsx)(VerifyCodeForm, {}) }));
|
|
412
|
+
}
|