@payez/next-mvp 4.1.9 → 4.1.11

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.
Files changed (164) hide show
  1. package/README.md +792 -792
  2. package/dist/api-handlers/auth/refresh.js +38 -15
  3. package/dist/auth/better-auth.js +4 -3
  4. package/dist/components/account/MobileNavDrawer.js +18 -18
  5. package/dist/components/account/UserAvatarMenu.js +1 -1
  6. package/dist/components/admin/AlertSettingsTab.js +40 -40
  7. package/dist/components/admin/LoggingSettingsTab.js +28 -28
  8. package/dist/lib/ensure-fresh-access-token.js +42 -8
  9. package/dist/lib/idp-fetch.js +25 -9
  10. package/dist/lib/session-store.d.ts +1 -0
  11. package/dist/lib/session-store.js +12 -8
  12. package/dist/lib/token-lifecycle.d.ts +2 -0
  13. package/dist/lib/token-lifecycle.js +21 -3
  14. package/dist/pages/login/page.js +28 -28
  15. package/dist/pages/settings/EnhancedSettingsPage.js +17 -17
  16. package/package.json +893 -893
  17. package/scripts/dev-broker.ps1 +35 -35
  18. package/scripts/dev-local.ps1 +45 -45
  19. package/src/api/auth-handler.ts +548 -548
  20. package/src/api-handlers/account/change-password.ts +142 -142
  21. package/src/api-handlers/account/update-phone.ts +79 -79
  22. package/src/api-handlers/account/verify-email.ts +125 -125
  23. package/src/api-handlers/account/verify-sms.ts +125 -125
  24. package/src/api-handlers/admin/analytics.ts +443 -443
  25. package/src/api-handlers/admin/audit.ts +223 -223
  26. package/src/api-handlers/admin/index.ts +63 -63
  27. package/src/api-handlers/admin/redis-sessions.ts +251 -251
  28. package/src/api-handlers/admin/sessions.ts +318 -318
  29. package/src/api-handlers/admin/site-logs.ts +365 -365
  30. package/src/api-handlers/admin/users.ts +242 -242
  31. package/src/api-handlers/admin/vibe-data.ts +324 -324
  32. package/src/api-handlers/auth/refresh.ts +705 -682
  33. package/src/api-handlers/auth/signout.ts +199 -199
  34. package/src/api-handlers/auth/status.ts +20 -20
  35. package/src/api-handlers/auth/update-session.ts +110 -110
  36. package/src/api-handlers/auth/verify-code.ts +112 -112
  37. package/src/api-handlers/session/refresh-viability.ts +36 -36
  38. package/src/api-handlers/test/force-expire.ts +60 -60
  39. package/src/auth/auth-decision.ts +229 -229
  40. package/src/auth/better-auth.ts +467 -466
  41. package/src/auth/route-config.ts +219 -219
  42. package/src/auth/types/auth-types.ts +555 -555
  43. package/src/auth/types/index.ts +7 -7
  44. package/src/auth/utils/idp-client.ts +445 -445
  45. package/src/auth/utils/index.ts +6 -6
  46. package/src/auth/utils/token-utils.ts +243 -243
  47. package/src/client/AuthContext.tsx +143 -143
  48. package/src/client/fetch-with-auth.ts +47 -47
  49. package/src/components/SessionSync.tsx +138 -138
  50. package/src/components/SignalRHealthCheck.tsx +131 -131
  51. package/src/components/account/MobileNavDrawer.tsx +305 -305
  52. package/src/components/account/UserAvatarMenu.tsx +266 -266
  53. package/src/components/account/index.ts +13 -13
  54. package/src/components/admin/AlertSettingsTab.tsx +728 -728
  55. package/src/components/admin/AnalyticsTab.tsx +703 -703
  56. package/src/components/admin/DataBrowserTab.tsx +505 -505
  57. package/src/components/admin/LoggingSettingsTab.tsx +665 -665
  58. package/src/components/admin/SessionsTab.tsx +414 -414
  59. package/src/components/admin/StatsTab.tsx +379 -379
  60. package/src/components/admin/VibeAdminLayout.tsx +187 -187
  61. package/src/components/admin/index.ts +59 -59
  62. package/src/components/auth/FederatedAuthSection.tsx +95 -95
  63. package/src/components/auth/ModeAwareLoginPage.tsx +135 -135
  64. package/src/components/auth/ModeAwareSignupPage.tsx +267 -267
  65. package/src/components/auth/TraditionalAuthSection.tsx +99 -99
  66. package/src/components/recovery/CompleteStep.tsx +36 -36
  67. package/src/components/recovery/InitiateRecoveryStep.tsx +68 -68
  68. package/src/components/recovery/SelectMethodStep.tsx +73 -73
  69. package/src/components/recovery/SetPasswordStep.tsx +97 -97
  70. package/src/components/recovery/VerifyCodeStep.tsx +90 -90
  71. package/src/components/reserved/ReservedRecoveryWarning.tsx +160 -160
  72. package/src/components/reserved/ReservedStatusBox.tsx +118 -118
  73. package/src/components/ui/BetaBadge.tsx +58 -58
  74. package/src/components/ui/Footer.tsx +93 -93
  75. package/src/config/env.ts +57 -57
  76. package/src/config/logger.ts +62 -62
  77. package/src/config/vibe-log-transport.ts +264 -264
  78. package/src/hooks/useAuth.ts +117 -117
  79. package/src/hooks/useAuthSettings.ts +97 -97
  80. package/src/hooks/useAvailableProviders.ts +120 -120
  81. package/src/hooks/usePasswordValidation.ts +127 -127
  82. package/src/hooks/usePublicAuthSettings.ts +149 -149
  83. package/src/hooks/useSessionExpiration.ts +101 -101
  84. package/src/hooks/useViabilitySession.ts +336 -336
  85. package/src/index.ts +60 -60
  86. package/src/lib/api-handler.ts +643 -643
  87. package/src/lib/app-slug.ts +178 -178
  88. package/src/lib/ensure-fresh-access-token.ts +369 -335
  89. package/src/lib/geolocation.ts +265 -265
  90. package/src/lib/idp-fetch.ts +26 -10
  91. package/src/lib/jwt-decode.ts +82 -82
  92. package/src/lib/roles.ts +177 -177
  93. package/src/lib/session-store.ts +4 -1
  94. package/src/lib/site-logger.ts +245 -245
  95. package/src/lib/standardized-client-api.ts +901 -901
  96. package/src/lib/test-aware-get-token.ts +41 -41
  97. package/src/lib/token-lifecycle.ts +30 -3
  98. package/src/lib/user-agent-parser.ts +252 -252
  99. package/src/logging/api/admin-analytics.ts +51 -51
  100. package/src/logging/api/audit-log.ts +53 -53
  101. package/src/logging/components/AdminAnalyticsLayout.tsx +49 -49
  102. package/src/logging/components/AuditLogViewer.tsx +125 -125
  103. package/src/logging/components/ErrorMetricsCard.tsx +98 -98
  104. package/src/logging/components/HealthMetricsCard.tsx +70 -70
  105. package/src/logging/hooks/useAdminAnalytics.ts +22 -22
  106. package/src/logging/hooks/useAuditLog.ts +24 -24
  107. package/src/logging/hooks/useErrorMetrics.ts +40 -40
  108. package/src/logging/hooks/useHealthMetrics.ts +44 -44
  109. package/src/logging/index.ts +18 -18
  110. package/src/logging/types/analytics.ts +81 -81
  111. package/src/logging/types/audit.ts +31 -31
  112. package/src/logging/types/index.ts +3 -3
  113. package/src/middleware/create-middleware.ts +663 -663
  114. package/src/middleware/rbac-check.ts +279 -279
  115. package/src/middleware/twofa-presets.ts +224 -224
  116. package/src/pages/admin-login/page.tsx +221 -221
  117. package/src/pages/admin-page-permissions/PagePermissionsAdminPage.tsx +527 -527
  118. package/src/pages/admin-page-permissions/index.ts +7 -7
  119. package/src/pages/admin-roles/RolesAdminPage.tsx +533 -533
  120. package/src/pages/admin-roles/modals.tsx +469 -469
  121. package/src/pages/client-admin/ClientSiteAdminPage.tsx +382 -382
  122. package/src/pages/client-admin/index.ts +33 -33
  123. package/src/pages/coming-soon/page.tsx +83 -83
  124. package/src/pages/login/page.tsx +456 -456
  125. package/src/pages/profile/EnhancedProfilePage.tsx +485 -485
  126. package/src/pages/profile/index.ts +9 -9
  127. package/src/pages/profile/page.tsx +166 -166
  128. package/src/pages/recovery/page.tsx +234 -234
  129. package/src/pages/roles/MyRolesPage.tsx +211 -211
  130. package/src/pages/roles/components.tsx +294 -294
  131. package/src/pages/roles/index.ts +17 -17
  132. package/src/pages/security/EnhancedSecurityPage.tsx +565 -565
  133. package/src/pages/security/index.ts +9 -9
  134. package/src/pages/security/page.tsx +507 -507
  135. package/src/pages/settings/EnhancedSettingsPage.tsx +642 -642
  136. package/src/pages/settings/index.ts +9 -9
  137. package/src/pages/settings/page.tsx +47 -47
  138. package/src/pages/showcase/ShowcasePage.tsx +532 -532
  139. package/src/pages/showcase/index.ts +13 -13
  140. package/src/pages/test-env/EmergencyLogoutPage.tsx +180 -180
  141. package/src/pages/test-env/JwtInspectPage.tsx +456 -456
  142. package/src/pages/test-env/RefreshTokenPage.tsx +157 -157
  143. package/src/pages/test-env/TestEnvPage.tsx +118 -118
  144. package/src/pages/test-env/index.ts +25 -25
  145. package/src/pages/verify-code/page.tsx +652 -652
  146. package/src/routes/account/update-phone.ts +13 -13
  147. package/src/routes/auth/logout.ts +108 -108
  148. package/src/routes/auth/nextauth.ts +45 -45
  149. package/src/routes/auth/settings.ts +75 -75
  150. package/src/routes/auth/viability.ts +224 -224
  151. package/src/server/auth-guard.ts +170 -170
  152. package/src/server/slim-middleware.ts +117 -117
  153. package/src/server/with-auth.ts +93 -93
  154. package/src/stores/authStore.ts +1899 -1899
  155. package/src/templates/instrumentation.ts +41 -41
  156. package/src/utils/logout.ts +30 -30
  157. package/src/vibe/client.ts +590 -590
  158. package/src/vibe/enterprise-auth.ts +208 -208
  159. package/src/vibe/errors.ts +185 -185
  160. package/src/vibe/generic.ts +431 -431
  161. package/src/vibe/hooks/index.ts +367 -367
  162. package/src/vibe/index.ts +132 -132
  163. package/src/vibe/sessions.ts +551 -551
  164. package/src/vibe/types.ts +577 -577
@@ -1,456 +1,456 @@
1
- /**
2
- * Themed Login Page for @payez/next-mvp
3
- *
4
- * DEPENDENCIES: Only React, Next.js, next-auth, and Tailwind CSS
5
- * NO shadcn/ui or other UI library required!
6
- *
7
- * FEATURES:
8
- * ✅ Atomic state management with visual feedback (submitting/error/success)
9
- * ✅ Enhanced error handling with user-friendly messages
10
- * ✅ Show/hide password toggle
11
- * ✅ Loading state management with timeouts
12
- * ✅ Proper autofill styling
13
- * ✅ Session expiration handling
14
- * ✅ Themeable styling via ThemeProvider
15
- * ✅ Placeholder for health check component
16
- *
17
- * USAGE:
18
- * 1. Import from @payez/next-mvp/pages/login
19
- * 2. Wrap your app with ThemeProvider to customize branding
20
- * 3. Optionally add your health check component
21
- */
22
-
23
- 'use client';
24
-
25
- import React, { useState, useEffect } from 'react';
26
- import { authClient } from '../../client/better-auth-client';
27
- import { useSearchParams } from 'next/navigation';
28
- import { Suspense } from 'react';
29
- import ReservedStatusBox from '../../components/reserved/ReservedStatusBox';
30
- import ReservedRecoveryWarning from '../../components/reserved/ReservedRecoveryWarning';
31
- import { useBranding, useColors, useLayout } from '../../theme/useTheme';
32
-
33
- function LoginForm() {
34
- const searchParams = useSearchParams();
35
- const callbackUrl = searchParams?.get('callbackUrl') || '/dashboard';
36
- const urlError = searchParams?.get('error');
37
-
38
- const { data: sessionData, isPending } = authClient.useSession();
39
- const session = sessionData;
40
- const status = isPending ? 'loading' : session ? 'authenticated' : 'unauthenticated';
41
- const branding = useBranding();
42
- const colors = useColors();
43
- const layout = useLayout();
44
-
45
- // Helper to create lighter/darker shades for hover states
46
- const adjustBrightness = (hex: string, percent: number) => {
47
- const num = parseInt(hex.replace('#', ''), 16);
48
- const amt = Math.round(2.55 * percent);
49
- const R = (num >> 16) + amt;
50
- const G = (num >> 8 & 0x00FF) + amt;
51
- const B = (num & 0x0000FF) + amt;
52
- return '#' + (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 +
53
- (G < 255 ? G < 1 ? 0 : G : 255) * 0x100 +
54
- (B < 255 ? B < 1 ? 0 : B : 255))
55
- .toString(16).slice(1);
56
- };
57
-
58
- // Get the primary button color from theme (defaults to primary, or uses component override)
59
- const buttonColor = colors.secondary || colors.primary || '#3b82f6';
60
- const buttonHoverColor = adjustBrightness(buttonColor, -10);
61
-
62
- // Form fields
63
- const [email, setEmail] = useState('');
64
- const [password, setPassword] = useState('');
65
- const [showPassword, setShowPassword] = useState(false);
66
-
67
- // Atomic state management - only ONE can be true at a time
68
- const [isSubmitting, setIsSubmitting] = useState(false);
69
- const [loginSuccess, setLoginSuccess] = useState(false);
70
- const [loginError, setLoginError] = useState<string | null>(null);
71
- const [loading, setLoading] = useState(false);
72
- const [showRecoveryOptions, setShowRecoveryOptions] = useState(false);
73
-
74
- // Force show form after timeout if stuck in loading
75
- const [forceShowForm, setForceShowForm] = useState(false);
76
-
77
- // Handle URL errors with user-friendly messages
78
- useEffect(() => {
79
- if (urlError) {
80
- let friendlyError: string | null = urlError;
81
-
82
- if (urlError === 'SessionExpired') {
83
- // Session expiration is normal - don't show as error
84
- console.log('[LOGIN] SessionExpired detected - normal behavior');
85
- friendlyError = null;
86
- } else if (urlError === 'ServiceUnavailable') {
87
- friendlyError = 'Authentication service is temporarily unavailable. Please try again in a few minutes.';
88
- } else if (urlError.startsWith("Unexpected token")) {
89
- friendlyError = 'An authentication error occurred. Please try signing in again.';
90
- } else if (urlError.includes('not valid JSON')) {
91
- friendlyError = 'An authentication error occurred. Please try signing in again.';
92
- } else if (urlError === 'CredentialsSignin') {
93
- friendlyError = 'Invalid email or password. Please try again.';
94
- }
95
-
96
- setLoginError(friendlyError);
97
- }
98
- }, [urlError]);
99
-
100
- // Timeout to prevent infinite loading states
101
- useEffect(() => {
102
- if (status === 'loading') {
103
- const timeout = setTimeout(() => {
104
- console.warn('[LOGIN] NextAuth status stuck in loading, forcing form display');
105
- setForceShowForm(true);
106
- }, 3000);
107
- return () => clearTimeout(timeout);
108
- }
109
- }, [status]);
110
-
111
- // Force show form after 1 second if no session
112
- useEffect(() => {
113
- const immediateTimeout = setTimeout(() => {
114
- if (status === 'loading' && !session) {
115
- console.log('[LOGIN] Force showing form after 1 second');
116
- setForceShowForm(true);
117
- }
118
- }, 1000);
119
- return () => clearTimeout(immediateTimeout);
120
- }, [status, session]);
121
-
122
- const handleSubmit = async (e: React.FormEvent) => {
123
- e.preventDefault();
124
-
125
- // Atomic state: set to submitting (clears error and success)
126
- setIsSubmitting(true);
127
- setLoading(true);
128
- setLoginError(null);
129
- setLoginSuccess(false);
130
-
131
- try {
132
- console.log('[LOGIN] Starting authentication...');
133
- const result = await authClient.signIn.email({
134
- email,
135
- password,
136
- callbackURL: callbackUrl,
137
- });
138
-
139
- if ((result as any)?.error) {
140
- console.log('[LOGIN] Authentication failed:', (result as any).error);
141
-
142
- setIsSubmitting(false);
143
- setLoading(false);
144
- setLoginSuccess(false);
145
-
146
- const errorMsg = typeof (result as any).error === 'object'
147
- ? ((result as any).error as any).message || 'Authentication failed'
148
- : String((result as any).error);
149
-
150
- if (errorMsg.includes('password') || errorMsg.includes('Password')) {
151
- console.log('[LOGIN] Password error detected - showing recovery options');
152
- setShowRecoveryOptions(true);
153
- setLoginError(errorMsg);
154
- } else if (errorMsg.includes('Unable to connect')) {
155
- setLoginError('The authentication service is currently unavailable. Please try again later.');
156
- } else {
157
- setLoginError(errorMsg);
158
- }
159
- return;
160
- }
161
-
162
- // Atomic state: set to success
163
- console.log('[LOGIN] Authentication successful!');
164
- setLoginSuccess(true);
165
- setLoginError(null);
166
- setIsSubmitting(false);
167
-
168
- // Get updated session
169
- const freshSession = await authClient.getSession();
170
- console.log('[LOGIN] Fresh session obtained, redirecting to 2FA...');
171
-
172
- // Redirect to verify-code for 2FA
173
- const verifyUrl = `/account-auth/verify-code?callbackUrl=${encodeURIComponent(callbackUrl)}`;
174
- console.log('[LOGIN] Redirecting to:', verifyUrl);
175
- window.location.href = verifyUrl;
176
-
177
- } catch (err) {
178
- console.error('[LOGIN] Unexpected error:', err);
179
-
180
- // Atomic state: set to error
181
- setIsSubmitting(false);
182
- setLoading(false);
183
- setLoginSuccess(false);
184
- setLoginError(err instanceof Error ? err.message : 'An error occurred during login');
185
- }
186
- };
187
-
188
- // Show loading spinner for initial loads
189
- if (!forceShowForm && !loginError && (loading || (status === 'loading' && !session))) {
190
- return (
191
- <div className={`flex flex-col items-center justify-center min-h-screen ${colors.background}`}>
192
- <svg className="animate-spin h-6 w-6" style={{ color: buttonColor }} viewBox="0 0 24 24" fill="none">
193
- <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
194
- <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z" />
195
- </svg>
196
- <p className={`mt-4 text-sm ${colors.muted}`}>
197
- {status === 'loading' ? 'Loading...' : 'Authenticating...'}
198
- </p>
199
- </div>
200
- );
201
- }
202
-
203
- return (
204
- <>
205
- {/* Dynamic styles for theme colors */}
206
- <style dangerouslySetInnerHTML={{__html: `
207
- .themed-input:focus {
208
- outline: none;
209
- border-color: ${buttonColor} !important;
210
- box-shadow: 0 0 0 2px ${buttonColor}40 !important;
211
- }
212
- .themed-button {
213
- background-color: ${buttonColor} !important;
214
- }
215
- .themed-button:hover:not(:disabled) {
216
- background-color: ${buttonHoverColor} !important;
217
- }
218
- .themed-link {
219
- color: ${buttonColor} !important;
220
- }
221
- .themed-link:hover {
222
- color: ${buttonHoverColor} !important;
223
- }
224
- .themed-status-submitting {
225
- background-color: ${buttonColor}1A !important;
226
- border-color: ${buttonColor}33 !important;
227
- }
228
- .themed-status-submitting-text {
229
- color: ${buttonColor} !important;
230
- }
231
- .themed-status-submitting svg {
232
- color: ${buttonColor} !important;
233
- }
234
- `}} />
235
- <div className={`min-h-screen flex items-center justify-center px-4 ${colors.background}`}>
236
- <div className="max-w-md w-full">
237
- {/* Card */}
238
- <div className={`rounded-2xl shadow-xl p-8 ${colors.card} ${colors.border} text-gray-800`}>
239
- {/* Header */}
240
- <div className="text-center mb-8">
241
- <h1 className="text-3xl font-bold mb-2" style={{ color: 'inherit' }}>
242
- {branding.tagline || 'Welcome Back'}
243
- </h1>
244
- <p className={colors.muted}>
245
- Sign in to your account
246
- </p>
247
- </div>
248
-
249
- {/* Login Form */}
250
- <form onSubmit={handleSubmit} className="space-y-6" data-testid="login-form">
251
- {/* Email Field */}
252
- <div>
253
- <label htmlFor="email" className="block text-sm font-medium mb-2" style={{ color: 'inherit' }}>
254
- Email Address
255
- </label>
256
- <input
257
- id="email"
258
- type="email"
259
- required
260
- autoFocus
261
- autoComplete="email"
262
- value={email}
263
- onChange={(e) => setEmail(e.target.value)}
264
- className={`themed-input w-full px-4 py-3 border border-gray-300 rounded-lg transition-colors`}
265
- placeholder="you@example.com"
266
- disabled={isSubmitting}
267
- style={{ backgroundColor: 'white', color: '#1f2937' }}
268
- />
269
- </div>
270
-
271
- {/* Password Field with Show/Hide Toggle */}
272
- <div>
273
- <label htmlFor="password" className="block text-sm font-medium mb-2" style={{ color: 'inherit' }}>
274
- Password
275
- </label>
276
- <div className="relative">
277
- <input
278
- id="password"
279
- type={showPassword ? "text" : "password"}
280
- required
281
- autoComplete="current-password"
282
- value={password}
283
- onChange={(e) => setPassword(e.target.value)}
284
- className={`themed-input w-full px-4 py-3 pr-12 border border-gray-300 rounded-lg transition-colors`}
285
- placeholder="••••••••"
286
- disabled={isSubmitting}
287
- style={{ backgroundColor: 'white', color: '#1f2937' }}
288
- />
289
- <button
290
- type="button"
291
- onClick={() => setShowPassword(!showPassword)}
292
- className="absolute right-3 top-1/2 transform -translate-y-1/2 hover:opacity-70"
293
- style={{ color: 'inherit', opacity: 0.7 }}
294
- aria-label={showPassword ? "Hide password" : "Show password"}
295
- >
296
- {showPassword ? (
297
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" className="w-5 h-5">
298
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.878 9.878L6.464 6.464m7.535 7.535l3.415 3.414M3 3l3.464 3.464M21 21l-3.415-3.414" />
299
- </svg>
300
- ) : (
301
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" className="w-5 h-5">
302
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
303
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
304
- </svg>
305
- )}
306
- </button>
307
- </div>
308
- </div>
309
-
310
- {/* Atomic Status Display - Deterministic Reserved Space (zero layout shift) */}
311
- <ReservedStatusBox
312
- candidates={[
313
- "Ready",
314
- "Authenticating...",
315
- "The authentication service is currently unavailable. Please try again later.",
316
- "Invalid email or password. Please try again.",
317
- "Login successful! Redirecting..."
318
- ]}
319
- containerClass="p-3 text-sm leading-relaxed rounded-lg border"
320
- iconSizePx={16}
321
- >
322
- {isSubmitting ? (
323
- /* Themed: Submitting */
324
- <div className="themed-status-submitting flex items-start space-x-2 p-3 rounded-lg">
325
- <svg className="animate-spin w-4 h-4 mt-0.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" style={{ color: buttonColor }}>
326
- <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
327
- <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"></path>
328
- </svg>
329
- <span className="themed-status-submitting-text text-sm leading-relaxed" style={{ color: buttonColor }}>Authenticating...</span>
330
- </div>
331
- ) : loginError ? (
332
- /* Red: Error */
333
- <div className="flex items-start space-x-2 p-3 rounded-lg bg-red-500/10 border border-red-500/20">
334
- <div className="w-4 h-4 bg-red-500 rounded-full mt-0.5 flex-shrink-0"></div>
335
- <span className="text-red-600 text-sm leading-relaxed">{loginError}</span>
336
- </div>
337
- ) : loginSuccess ? (
338
- /* Green: Success */
339
- <div className="flex items-start space-x-2 p-3 rounded-lg bg-green-500/10 border border-green-500/20">
340
- <div className="w-4 h-4 bg-green-500 rounded-full mt-0.5 flex-shrink-0"></div>
341
- <span className="text-green-600 text-sm leading-relaxed">Login successful! Redirecting...</span>
342
- </div>
343
- ) : (
344
- /* Ready State / Health Check Placeholder */
345
- <div className="flex items-start space-x-2 p-3 rounded-lg bg-green-500/10 border border-green-500/20">
346
- <div className="w-4 h-4 bg-green-500 rounded-full mt-0.5 flex-shrink-0"></div>
347
- <span className="text-green-600 text-sm leading-relaxed">Ready</span>
348
- {/*
349
- CUSTOMIZATION: Replace above with your health check component
350
- Example: <SignalRHealthCheck />
351
- Or any real-time health status component
352
- */}
353
- </div>
354
- )}
355
- </ReservedStatusBox>
356
-
357
- {/* Account Recovery Options - Deterministic Reserved Space (zero layout shift) */}
358
- <ReservedRecoveryWarning
359
- show={showRecoveryOptions}
360
- titleText="Account Lockout Warning"
361
- bodyText="Your account will be locked after one more failed attempt. Need help?"
362
- actionLabel="Start Account Recovery"
363
- containerClass="p-4 bg-amber-50 border border-amber-200 rounded-lg"
364
- titleClass="text-amber-900 font-medium mb-2"
365
- bodyClass="text-amber-800 text-sm mb-3"
366
- buttonClass="w-full bg-amber-600 hover:bg-amber-700 text-white font-medium py-2 px-4 rounded-md text-sm transition-colors"
367
- iconSizePx={20}
368
- >
369
- {showRecoveryOptions && (
370
- <div className="p-4 bg-amber-50 border border-amber-200 rounded-lg">
371
- <div className="flex items-start space-x-3">
372
- <svg className="w-5 h-5 text-amber-600 mt-0.5 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
373
- <path fillRule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clipRule="evenodd" />
374
- </svg>
375
- <div className="flex-1">
376
- <h3 className="text-amber-900 font-medium mb-2">Account Lockout Warning</h3>
377
- <p className="text-amber-800 text-sm mb-3">
378
- Your account will be locked after one more failed attempt. Need help?
379
- </p>
380
- <button
381
- type="button"
382
- onClick={() => window.location.href = `/account-auth/recovery?email=${encodeURIComponent(email)}`}
383
- className="w-full bg-amber-600 hover:bg-amber-700 text-white font-medium py-2 px-4 rounded-md text-sm transition-colors"
384
- >
385
- Start Account Recovery
386
- </button>
387
- </div>
388
- </div>
389
- </div>
390
- )}
391
- </ReservedRecoveryWarning>
392
-
393
- {/* Submit Button */}
394
- <button
395
- type="submit"
396
- disabled={isSubmitting}
397
- className="themed-button w-full text-white font-semibold py-3 px-4 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center"
398
- >
399
- {isSubmitting ? (
400
- <>
401
- <svg className="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
402
- <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
403
- <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"></path>
404
- </svg>
405
- Signing in...
406
- </>
407
- ) : (
408
- 'Sign In'
409
- )}
410
- </button>
411
- </form>
412
-
413
- {/* Footer Links */}
414
- <div className={`mt-6 text-center text-sm ${colors.muted}`}>
415
- <a href="/account-auth/recovery" className="themed-link hover:underline">
416
- Start account recovery
417
- </a>
418
- </div>
419
- </div>
420
-
421
- {/* Additional Info */}
422
- <p className={`mt-4 text-center text-sm ${colors.muted}`}>
423
- Don't have an account?{' '}
424
- <a href="/account-auth/register" className="themed-link font-medium hover:underline">
425
- Sign up
426
- </a>
427
- </p>
428
- </div>
429
- </div>
430
- </>
431
- );
432
- }
433
-
434
- function LoginPageFallback() {
435
- const colors = useColors();
436
- const buttonColor = colors.secondary || colors.primary || '#11B588';
437
- return (
438
- <div className={`min-h-screen flex items-center justify-center ${colors.background}`}>
439
- <div className="text-center">
440
- <svg className="animate-spin h-10 w-10 mx-auto" style={{ color: buttonColor }} xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
441
- <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
442
- <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"></path>
443
- </svg>
444
- <p className={`mt-4 ${colors.muted}`}>Loading...</p>
445
- </div>
446
- </div>
447
- );
448
- }
449
-
450
- export default function LoginPage() {
451
- return (
452
- <Suspense fallback={<LoginPageFallback />}>
453
- <LoginForm />
454
- </Suspense>
455
- );
456
- }
1
+ /**
2
+ * Themed Login Page for @payez/next-mvp
3
+ *
4
+ * DEPENDENCIES: Only React, Next.js, next-auth, and Tailwind CSS
5
+ * NO shadcn/ui or other UI library required!
6
+ *
7
+ * FEATURES:
8
+ * ✅ Atomic state management with visual feedback (submitting/error/success)
9
+ * ✅ Enhanced error handling with user-friendly messages
10
+ * ✅ Show/hide password toggle
11
+ * ✅ Loading state management with timeouts
12
+ * ✅ Proper autofill styling
13
+ * ✅ Session expiration handling
14
+ * ✅ Themeable styling via ThemeProvider
15
+ * ✅ Placeholder for health check component
16
+ *
17
+ * USAGE:
18
+ * 1. Import from @payez/next-mvp/pages/login
19
+ * 2. Wrap your app with ThemeProvider to customize branding
20
+ * 3. Optionally add your health check component
21
+ */
22
+
23
+ 'use client';
24
+
25
+ import React, { useState, useEffect } from 'react';
26
+ import { authClient } from '../../client/better-auth-client';
27
+ import { useSearchParams } from 'next/navigation';
28
+ import { Suspense } from 'react';
29
+ import ReservedStatusBox from '../../components/reserved/ReservedStatusBox';
30
+ import ReservedRecoveryWarning from '../../components/reserved/ReservedRecoveryWarning';
31
+ import { useBranding, useColors, useLayout } from '../../theme/useTheme';
32
+
33
+ function LoginForm() {
34
+ const searchParams = useSearchParams();
35
+ const callbackUrl = searchParams?.get('callbackUrl') || '/dashboard';
36
+ const urlError = searchParams?.get('error');
37
+
38
+ const { data: sessionData, isPending } = authClient.useSession();
39
+ const session = sessionData;
40
+ const status = isPending ? 'loading' : session ? 'authenticated' : 'unauthenticated';
41
+ const branding = useBranding();
42
+ const colors = useColors();
43
+ const layout = useLayout();
44
+
45
+ // Helper to create lighter/darker shades for hover states
46
+ const adjustBrightness = (hex: string, percent: number) => {
47
+ const num = parseInt(hex.replace('#', ''), 16);
48
+ const amt = Math.round(2.55 * percent);
49
+ const R = (num >> 16) + amt;
50
+ const G = (num >> 8 & 0x00FF) + amt;
51
+ const B = (num & 0x0000FF) + amt;
52
+ return '#' + (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 +
53
+ (G < 255 ? G < 1 ? 0 : G : 255) * 0x100 +
54
+ (B < 255 ? B < 1 ? 0 : B : 255))
55
+ .toString(16).slice(1);
56
+ };
57
+
58
+ // Get the primary button color from theme (defaults to primary, or uses component override)
59
+ const buttonColor = colors.secondary || colors.primary || '#3b82f6';
60
+ const buttonHoverColor = adjustBrightness(buttonColor, -10);
61
+
62
+ // Form fields
63
+ const [email, setEmail] = useState('');
64
+ const [password, setPassword] = useState('');
65
+ const [showPassword, setShowPassword] = useState(false);
66
+
67
+ // Atomic state management - only ONE can be true at a time
68
+ const [isSubmitting, setIsSubmitting] = useState(false);
69
+ const [loginSuccess, setLoginSuccess] = useState(false);
70
+ const [loginError, setLoginError] = useState<string | null>(null);
71
+ const [loading, setLoading] = useState(false);
72
+ const [showRecoveryOptions, setShowRecoveryOptions] = useState(false);
73
+
74
+ // Force show form after timeout if stuck in loading
75
+ const [forceShowForm, setForceShowForm] = useState(false);
76
+
77
+ // Handle URL errors with user-friendly messages
78
+ useEffect(() => {
79
+ if (urlError) {
80
+ let friendlyError: string | null = urlError;
81
+
82
+ if (urlError === 'SessionExpired') {
83
+ // Session expiration is normal - don't show as error
84
+ console.log('[LOGIN] SessionExpired detected - normal behavior');
85
+ friendlyError = null;
86
+ } else if (urlError === 'ServiceUnavailable') {
87
+ friendlyError = 'Authentication service is temporarily unavailable. Please try again in a few minutes.';
88
+ } else if (urlError.startsWith("Unexpected token")) {
89
+ friendlyError = 'An authentication error occurred. Please try signing in again.';
90
+ } else if (urlError.includes('not valid JSON')) {
91
+ friendlyError = 'An authentication error occurred. Please try signing in again.';
92
+ } else if (urlError === 'CredentialsSignin') {
93
+ friendlyError = 'Invalid email or password. Please try again.';
94
+ }
95
+
96
+ setLoginError(friendlyError);
97
+ }
98
+ }, [urlError]);
99
+
100
+ // Timeout to prevent infinite loading states
101
+ useEffect(() => {
102
+ if (status === 'loading') {
103
+ const timeout = setTimeout(() => {
104
+ console.warn('[LOGIN] NextAuth status stuck in loading, forcing form display');
105
+ setForceShowForm(true);
106
+ }, 3000);
107
+ return () => clearTimeout(timeout);
108
+ }
109
+ }, [status]);
110
+
111
+ // Force show form after 1 second if no session
112
+ useEffect(() => {
113
+ const immediateTimeout = setTimeout(() => {
114
+ if (status === 'loading' && !session) {
115
+ console.log('[LOGIN] Force showing form after 1 second');
116
+ setForceShowForm(true);
117
+ }
118
+ }, 1000);
119
+ return () => clearTimeout(immediateTimeout);
120
+ }, [status, session]);
121
+
122
+ const handleSubmit = async (e: React.FormEvent) => {
123
+ e.preventDefault();
124
+
125
+ // Atomic state: set to submitting (clears error and success)
126
+ setIsSubmitting(true);
127
+ setLoading(true);
128
+ setLoginError(null);
129
+ setLoginSuccess(false);
130
+
131
+ try {
132
+ console.log('[LOGIN] Starting authentication...');
133
+ const result = await authClient.signIn.email({
134
+ email,
135
+ password,
136
+ callbackURL: callbackUrl,
137
+ });
138
+
139
+ if ((result as any)?.error) {
140
+ console.log('[LOGIN] Authentication failed:', (result as any).error);
141
+
142
+ setIsSubmitting(false);
143
+ setLoading(false);
144
+ setLoginSuccess(false);
145
+
146
+ const errorMsg = typeof (result as any).error === 'object'
147
+ ? ((result as any).error as any).message || 'Authentication failed'
148
+ : String((result as any).error);
149
+
150
+ if (errorMsg.includes('password') || errorMsg.includes('Password')) {
151
+ console.log('[LOGIN] Password error detected - showing recovery options');
152
+ setShowRecoveryOptions(true);
153
+ setLoginError(errorMsg);
154
+ } else if (errorMsg.includes('Unable to connect')) {
155
+ setLoginError('The authentication service is currently unavailable. Please try again later.');
156
+ } else {
157
+ setLoginError(errorMsg);
158
+ }
159
+ return;
160
+ }
161
+
162
+ // Atomic state: set to success
163
+ console.log('[LOGIN] Authentication successful!');
164
+ setLoginSuccess(true);
165
+ setLoginError(null);
166
+ setIsSubmitting(false);
167
+
168
+ // Get updated session
169
+ const freshSession = await authClient.getSession();
170
+ console.log('[LOGIN] Fresh session obtained, redirecting to 2FA...');
171
+
172
+ // Redirect to verify-code for 2FA
173
+ const verifyUrl = `/account-auth/verify-code?callbackUrl=${encodeURIComponent(callbackUrl)}`;
174
+ console.log('[LOGIN] Redirecting to:', verifyUrl);
175
+ window.location.href = verifyUrl;
176
+
177
+ } catch (err) {
178
+ console.error('[LOGIN] Unexpected error:', err);
179
+
180
+ // Atomic state: set to error
181
+ setIsSubmitting(false);
182
+ setLoading(false);
183
+ setLoginSuccess(false);
184
+ setLoginError(err instanceof Error ? err.message : 'An error occurred during login');
185
+ }
186
+ };
187
+
188
+ // Show loading spinner for initial loads
189
+ if (!forceShowForm && !loginError && (loading || (status === 'loading' && !session))) {
190
+ return (
191
+ <div className={`flex flex-col items-center justify-center min-h-screen ${colors.background}`}>
192
+ <svg className="animate-spin h-6 w-6" style={{ color: buttonColor }} viewBox="0 0 24 24" fill="none">
193
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
194
+ <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z" />
195
+ </svg>
196
+ <p className={`mt-4 text-sm ${colors.muted}`}>
197
+ {status === 'loading' ? 'Loading...' : 'Authenticating...'}
198
+ </p>
199
+ </div>
200
+ );
201
+ }
202
+
203
+ return (
204
+ <>
205
+ {/* Dynamic styles for theme colors */}
206
+ <style dangerouslySetInnerHTML={{__html: `
207
+ .themed-input:focus {
208
+ outline: none;
209
+ border-color: ${buttonColor} !important;
210
+ box-shadow: 0 0 0 2px ${buttonColor}40 !important;
211
+ }
212
+ .themed-button {
213
+ background-color: ${buttonColor} !important;
214
+ }
215
+ .themed-button:hover:not(:disabled) {
216
+ background-color: ${buttonHoverColor} !important;
217
+ }
218
+ .themed-link {
219
+ color: ${buttonColor} !important;
220
+ }
221
+ .themed-link:hover {
222
+ color: ${buttonHoverColor} !important;
223
+ }
224
+ .themed-status-submitting {
225
+ background-color: ${buttonColor}1A !important;
226
+ border-color: ${buttonColor}33 !important;
227
+ }
228
+ .themed-status-submitting-text {
229
+ color: ${buttonColor} !important;
230
+ }
231
+ .themed-status-submitting svg {
232
+ color: ${buttonColor} !important;
233
+ }
234
+ `}} />
235
+ <div className={`min-h-screen flex items-center justify-center px-4 ${colors.background}`}>
236
+ <div className="max-w-md w-full">
237
+ {/* Card */}
238
+ <div className={`rounded-2xl shadow-xl p-8 ${colors.card} ${colors.border} text-gray-800`}>
239
+ {/* Header */}
240
+ <div className="text-center mb-8">
241
+ <h1 className="text-3xl font-bold mb-2" style={{ color: 'inherit' }}>
242
+ {branding.tagline || 'Welcome Back'}
243
+ </h1>
244
+ <p className={colors.muted}>
245
+ Sign in to your account
246
+ </p>
247
+ </div>
248
+
249
+ {/* Login Form */}
250
+ <form onSubmit={handleSubmit} className="space-y-6" data-testid="login-form">
251
+ {/* Email Field */}
252
+ <div>
253
+ <label htmlFor="email" className="block text-sm font-medium mb-2" style={{ color: 'inherit' }}>
254
+ Email Address
255
+ </label>
256
+ <input
257
+ id="email"
258
+ type="email"
259
+ required
260
+ autoFocus
261
+ autoComplete="email"
262
+ value={email}
263
+ onChange={(e) => setEmail(e.target.value)}
264
+ className={`themed-input w-full px-4 py-3 border border-gray-300 rounded-lg transition-colors`}
265
+ placeholder="you@example.com"
266
+ disabled={isSubmitting}
267
+ style={{ backgroundColor: 'white', color: '#1f2937' }}
268
+ />
269
+ </div>
270
+
271
+ {/* Password Field with Show/Hide Toggle */}
272
+ <div>
273
+ <label htmlFor="password" className="block text-sm font-medium mb-2" style={{ color: 'inherit' }}>
274
+ Password
275
+ </label>
276
+ <div className="relative">
277
+ <input
278
+ id="password"
279
+ type={showPassword ? "text" : "password"}
280
+ required
281
+ autoComplete="current-password"
282
+ value={password}
283
+ onChange={(e) => setPassword(e.target.value)}
284
+ className={`themed-input w-full px-4 py-3 pr-12 border border-gray-300 rounded-lg transition-colors`}
285
+ placeholder="••••••••"
286
+ disabled={isSubmitting}
287
+ style={{ backgroundColor: 'white', color: '#1f2937' }}
288
+ />
289
+ <button
290
+ type="button"
291
+ onClick={() => setShowPassword(!showPassword)}
292
+ className="absolute right-3 top-1/2 transform -translate-y-1/2 hover:opacity-70"
293
+ style={{ color: 'inherit', opacity: 0.7 }}
294
+ aria-label={showPassword ? "Hide password" : "Show password"}
295
+ >
296
+ {showPassword ? (
297
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" className="w-5 h-5">
298
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.878 9.878L6.464 6.464m7.535 7.535l3.415 3.414M3 3l3.464 3.464M21 21l-3.415-3.414" />
299
+ </svg>
300
+ ) : (
301
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" className="w-5 h-5">
302
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
303
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
304
+ </svg>
305
+ )}
306
+ </button>
307
+ </div>
308
+ </div>
309
+
310
+ {/* Atomic Status Display - Deterministic Reserved Space (zero layout shift) */}
311
+ <ReservedStatusBox
312
+ candidates={[
313
+ "Ready",
314
+ "Authenticating...",
315
+ "The authentication service is currently unavailable. Please try again later.",
316
+ "Invalid email or password. Please try again.",
317
+ "Login successful! Redirecting..."
318
+ ]}
319
+ containerClass="p-3 text-sm leading-relaxed rounded-lg border"
320
+ iconSizePx={16}
321
+ >
322
+ {isSubmitting ? (
323
+ /* Themed: Submitting */
324
+ <div className="themed-status-submitting flex items-start space-x-2 p-3 rounded-lg">
325
+ <svg className="animate-spin w-4 h-4 mt-0.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" style={{ color: buttonColor }}>
326
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
327
+ <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"></path>
328
+ </svg>
329
+ <span className="themed-status-submitting-text text-sm leading-relaxed" style={{ color: buttonColor }}>Authenticating...</span>
330
+ </div>
331
+ ) : loginError ? (
332
+ /* Red: Error */
333
+ <div className="flex items-start space-x-2 p-3 rounded-lg bg-red-500/10 border border-red-500/20">
334
+ <div className="w-4 h-4 bg-red-500 rounded-full mt-0.5 flex-shrink-0"></div>
335
+ <span className="text-red-600 text-sm leading-relaxed">{loginError}</span>
336
+ </div>
337
+ ) : loginSuccess ? (
338
+ /* Green: Success */
339
+ <div className="flex items-start space-x-2 p-3 rounded-lg bg-green-500/10 border border-green-500/20">
340
+ <div className="w-4 h-4 bg-green-500 rounded-full mt-0.5 flex-shrink-0"></div>
341
+ <span className="text-green-600 text-sm leading-relaxed">Login successful! Redirecting...</span>
342
+ </div>
343
+ ) : (
344
+ /* Ready State / Health Check Placeholder */
345
+ <div className="flex items-start space-x-2 p-3 rounded-lg bg-green-500/10 border border-green-500/20">
346
+ <div className="w-4 h-4 bg-green-500 rounded-full mt-0.5 flex-shrink-0"></div>
347
+ <span className="text-green-600 text-sm leading-relaxed">Ready</span>
348
+ {/*
349
+ CUSTOMIZATION: Replace above with your health check component
350
+ Example: <SignalRHealthCheck />
351
+ Or any real-time health status component
352
+ */}
353
+ </div>
354
+ )}
355
+ </ReservedStatusBox>
356
+
357
+ {/* Account Recovery Options - Deterministic Reserved Space (zero layout shift) */}
358
+ <ReservedRecoveryWarning
359
+ show={showRecoveryOptions}
360
+ titleText="Account Lockout Warning"
361
+ bodyText="Your account will be locked after one more failed attempt. Need help?"
362
+ actionLabel="Start Account Recovery"
363
+ containerClass="p-4 bg-amber-50 border border-amber-200 rounded-lg"
364
+ titleClass="text-amber-900 font-medium mb-2"
365
+ bodyClass="text-amber-800 text-sm mb-3"
366
+ buttonClass="w-full bg-amber-600 hover:bg-amber-700 text-white font-medium py-2 px-4 rounded-md text-sm transition-colors"
367
+ iconSizePx={20}
368
+ >
369
+ {showRecoveryOptions && (
370
+ <div className="p-4 bg-amber-50 border border-amber-200 rounded-lg">
371
+ <div className="flex items-start space-x-3">
372
+ <svg className="w-5 h-5 text-amber-600 mt-0.5 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
373
+ <path fillRule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clipRule="evenodd" />
374
+ </svg>
375
+ <div className="flex-1">
376
+ <h3 className="text-amber-900 font-medium mb-2">Account Lockout Warning</h3>
377
+ <p className="text-amber-800 text-sm mb-3">
378
+ Your account will be locked after one more failed attempt. Need help?
379
+ </p>
380
+ <button
381
+ type="button"
382
+ onClick={() => window.location.href = `/account-auth/recovery?email=${encodeURIComponent(email)}`}
383
+ className="w-full bg-amber-600 hover:bg-amber-700 text-white font-medium py-2 px-4 rounded-md text-sm transition-colors"
384
+ >
385
+ Start Account Recovery
386
+ </button>
387
+ </div>
388
+ </div>
389
+ </div>
390
+ )}
391
+ </ReservedRecoveryWarning>
392
+
393
+ {/* Submit Button */}
394
+ <button
395
+ type="submit"
396
+ disabled={isSubmitting}
397
+ className="themed-button w-full text-white font-semibold py-3 px-4 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center"
398
+ >
399
+ {isSubmitting ? (
400
+ <>
401
+ <svg className="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
402
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
403
+ <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"></path>
404
+ </svg>
405
+ Signing in...
406
+ </>
407
+ ) : (
408
+ 'Sign In'
409
+ )}
410
+ </button>
411
+ </form>
412
+
413
+ {/* Footer Links */}
414
+ <div className={`mt-6 text-center text-sm ${colors.muted}`}>
415
+ <a href="/account-auth/recovery" className="themed-link hover:underline">
416
+ Start account recovery
417
+ </a>
418
+ </div>
419
+ </div>
420
+
421
+ {/* Additional Info */}
422
+ <p className={`mt-4 text-center text-sm ${colors.muted}`}>
423
+ Don't have an account?{' '}
424
+ <a href="/account-auth/register" className="themed-link font-medium hover:underline">
425
+ Sign up
426
+ </a>
427
+ </p>
428
+ </div>
429
+ </div>
430
+ </>
431
+ );
432
+ }
433
+
434
+ function LoginPageFallback() {
435
+ const colors = useColors();
436
+ const buttonColor = colors.secondary || colors.primary || '#11B588';
437
+ return (
438
+ <div className={`min-h-screen flex items-center justify-center ${colors.background}`}>
439
+ <div className="text-center">
440
+ <svg className="animate-spin h-10 w-10 mx-auto" style={{ color: buttonColor }} xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
441
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
442
+ <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"></path>
443
+ </svg>
444
+ <p className={`mt-4 ${colors.muted}`}>Loading...</p>
445
+ </div>
446
+ </div>
447
+ );
448
+ }
449
+
450
+ export default function LoginPage() {
451
+ return (
452
+ <Suspense fallback={<LoginPageFallback />}>
453
+ <LoginForm />
454
+ </Suspense>
455
+ );
456
+ }