@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.
- package/README.md +792 -792
- package/dist/api-handlers/auth/refresh.js +38 -15
- package/dist/auth/better-auth.js +4 -3
- package/dist/components/account/MobileNavDrawer.js +18 -18
- package/dist/components/account/UserAvatarMenu.js +1 -1
- package/dist/components/admin/AlertSettingsTab.js +40 -40
- package/dist/components/admin/LoggingSettingsTab.js +28 -28
- package/dist/lib/ensure-fresh-access-token.js +42 -8
- package/dist/lib/idp-fetch.js +25 -9
- package/dist/lib/session-store.d.ts +1 -0
- package/dist/lib/session-store.js +12 -8
- package/dist/lib/token-lifecycle.d.ts +2 -0
- package/dist/lib/token-lifecycle.js +21 -3
- package/dist/pages/login/page.js +28 -28
- package/dist/pages/settings/EnhancedSettingsPage.js +17 -17
- package/package.json +893 -893
- package/scripts/dev-broker.ps1 +35 -35
- package/scripts/dev-local.ps1 +45 -45
- package/src/api/auth-handler.ts +548 -548
- package/src/api-handlers/account/change-password.ts +142 -142
- package/src/api-handlers/account/update-phone.ts +79 -79
- package/src/api-handlers/account/verify-email.ts +125 -125
- package/src/api-handlers/account/verify-sms.ts +125 -125
- package/src/api-handlers/admin/analytics.ts +443 -443
- package/src/api-handlers/admin/audit.ts +223 -223
- package/src/api-handlers/admin/index.ts +63 -63
- package/src/api-handlers/admin/redis-sessions.ts +251 -251
- package/src/api-handlers/admin/sessions.ts +318 -318
- package/src/api-handlers/admin/site-logs.ts +365 -365
- package/src/api-handlers/admin/users.ts +242 -242
- package/src/api-handlers/admin/vibe-data.ts +324 -324
- package/src/api-handlers/auth/refresh.ts +705 -682
- package/src/api-handlers/auth/signout.ts +199 -199
- package/src/api-handlers/auth/status.ts +20 -20
- package/src/api-handlers/auth/update-session.ts +110 -110
- package/src/api-handlers/auth/verify-code.ts +112 -112
- package/src/api-handlers/session/refresh-viability.ts +36 -36
- package/src/api-handlers/test/force-expire.ts +60 -60
- package/src/auth/auth-decision.ts +229 -229
- package/src/auth/better-auth.ts +467 -466
- package/src/auth/route-config.ts +219 -219
- package/src/auth/types/auth-types.ts +555 -555
- package/src/auth/types/index.ts +7 -7
- package/src/auth/utils/idp-client.ts +445 -445
- package/src/auth/utils/index.ts +6 -6
- package/src/auth/utils/token-utils.ts +243 -243
- package/src/client/AuthContext.tsx +143 -143
- package/src/client/fetch-with-auth.ts +47 -47
- package/src/components/SessionSync.tsx +138 -138
- package/src/components/SignalRHealthCheck.tsx +131 -131
- package/src/components/account/MobileNavDrawer.tsx +305 -305
- package/src/components/account/UserAvatarMenu.tsx +266 -266
- package/src/components/account/index.ts +13 -13
- package/src/components/admin/AlertSettingsTab.tsx +728 -728
- package/src/components/admin/AnalyticsTab.tsx +703 -703
- package/src/components/admin/DataBrowserTab.tsx +505 -505
- package/src/components/admin/LoggingSettingsTab.tsx +665 -665
- package/src/components/admin/SessionsTab.tsx +414 -414
- package/src/components/admin/StatsTab.tsx +379 -379
- package/src/components/admin/VibeAdminLayout.tsx +187 -187
- package/src/components/admin/index.ts +59 -59
- package/src/components/auth/FederatedAuthSection.tsx +95 -95
- package/src/components/auth/ModeAwareLoginPage.tsx +135 -135
- package/src/components/auth/ModeAwareSignupPage.tsx +267 -267
- package/src/components/auth/TraditionalAuthSection.tsx +99 -99
- package/src/components/recovery/CompleteStep.tsx +36 -36
- package/src/components/recovery/InitiateRecoveryStep.tsx +68 -68
- package/src/components/recovery/SelectMethodStep.tsx +73 -73
- package/src/components/recovery/SetPasswordStep.tsx +97 -97
- package/src/components/recovery/VerifyCodeStep.tsx +90 -90
- package/src/components/reserved/ReservedRecoveryWarning.tsx +160 -160
- package/src/components/reserved/ReservedStatusBox.tsx +118 -118
- package/src/components/ui/BetaBadge.tsx +58 -58
- package/src/components/ui/Footer.tsx +93 -93
- package/src/config/env.ts +57 -57
- package/src/config/logger.ts +62 -62
- package/src/config/vibe-log-transport.ts +264 -264
- package/src/hooks/useAuth.ts +117 -117
- package/src/hooks/useAuthSettings.ts +97 -97
- package/src/hooks/useAvailableProviders.ts +120 -120
- package/src/hooks/usePasswordValidation.ts +127 -127
- package/src/hooks/usePublicAuthSettings.ts +149 -149
- package/src/hooks/useSessionExpiration.ts +101 -101
- package/src/hooks/useViabilitySession.ts +336 -336
- package/src/index.ts +60 -60
- package/src/lib/api-handler.ts +643 -643
- package/src/lib/app-slug.ts +178 -178
- package/src/lib/ensure-fresh-access-token.ts +369 -335
- package/src/lib/geolocation.ts +265 -265
- package/src/lib/idp-fetch.ts +26 -10
- package/src/lib/jwt-decode.ts +82 -82
- package/src/lib/roles.ts +177 -177
- package/src/lib/session-store.ts +4 -1
- package/src/lib/site-logger.ts +245 -245
- package/src/lib/standardized-client-api.ts +901 -901
- package/src/lib/test-aware-get-token.ts +41 -41
- package/src/lib/token-lifecycle.ts +30 -3
- package/src/lib/user-agent-parser.ts +252 -252
- package/src/logging/api/admin-analytics.ts +51 -51
- package/src/logging/api/audit-log.ts +53 -53
- package/src/logging/components/AdminAnalyticsLayout.tsx +49 -49
- package/src/logging/components/AuditLogViewer.tsx +125 -125
- package/src/logging/components/ErrorMetricsCard.tsx +98 -98
- package/src/logging/components/HealthMetricsCard.tsx +70 -70
- package/src/logging/hooks/useAdminAnalytics.ts +22 -22
- package/src/logging/hooks/useAuditLog.ts +24 -24
- package/src/logging/hooks/useErrorMetrics.ts +40 -40
- package/src/logging/hooks/useHealthMetrics.ts +44 -44
- package/src/logging/index.ts +18 -18
- package/src/logging/types/analytics.ts +81 -81
- package/src/logging/types/audit.ts +31 -31
- package/src/logging/types/index.ts +3 -3
- package/src/middleware/create-middleware.ts +663 -663
- package/src/middleware/rbac-check.ts +279 -279
- package/src/middleware/twofa-presets.ts +224 -224
- package/src/pages/admin-login/page.tsx +221 -221
- package/src/pages/admin-page-permissions/PagePermissionsAdminPage.tsx +527 -527
- package/src/pages/admin-page-permissions/index.ts +7 -7
- package/src/pages/admin-roles/RolesAdminPage.tsx +533 -533
- package/src/pages/admin-roles/modals.tsx +469 -469
- package/src/pages/client-admin/ClientSiteAdminPage.tsx +382 -382
- package/src/pages/client-admin/index.ts +33 -33
- package/src/pages/coming-soon/page.tsx +83 -83
- package/src/pages/login/page.tsx +456 -456
- package/src/pages/profile/EnhancedProfilePage.tsx +485 -485
- package/src/pages/profile/index.ts +9 -9
- package/src/pages/profile/page.tsx +166 -166
- package/src/pages/recovery/page.tsx +234 -234
- package/src/pages/roles/MyRolesPage.tsx +211 -211
- package/src/pages/roles/components.tsx +294 -294
- package/src/pages/roles/index.ts +17 -17
- package/src/pages/security/EnhancedSecurityPage.tsx +565 -565
- package/src/pages/security/index.ts +9 -9
- package/src/pages/security/page.tsx +507 -507
- package/src/pages/settings/EnhancedSettingsPage.tsx +642 -642
- package/src/pages/settings/index.ts +9 -9
- package/src/pages/settings/page.tsx +47 -47
- package/src/pages/showcase/ShowcasePage.tsx +532 -532
- package/src/pages/showcase/index.ts +13 -13
- package/src/pages/test-env/EmergencyLogoutPage.tsx +180 -180
- package/src/pages/test-env/JwtInspectPage.tsx +456 -456
- package/src/pages/test-env/RefreshTokenPage.tsx +157 -157
- package/src/pages/test-env/TestEnvPage.tsx +118 -118
- package/src/pages/test-env/index.ts +25 -25
- package/src/pages/verify-code/page.tsx +652 -652
- package/src/routes/account/update-phone.ts +13 -13
- package/src/routes/auth/logout.ts +108 -108
- package/src/routes/auth/nextauth.ts +45 -45
- package/src/routes/auth/settings.ts +75 -75
- package/src/routes/auth/viability.ts +224 -224
- package/src/server/auth-guard.ts +170 -170
- package/src/server/slim-middleware.ts +117 -117
- package/src/server/with-auth.ts +93 -93
- package/src/stores/authStore.ts +1899 -1899
- package/src/templates/instrumentation.ts +41 -41
- package/src/utils/logout.ts +30 -30
- package/src/vibe/client.ts +590 -590
- package/src/vibe/enterprise-auth.ts +208 -208
- package/src/vibe/errors.ts +185 -185
- package/src/vibe/generic.ts +431 -431
- package/src/vibe/hooks/index.ts +367 -367
- package/src/vibe/index.ts +132 -132
- package/src/vibe/sessions.ts +551 -551
- package/src/vibe/types.ts +577 -577
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Feature Showcase Page
|
|
3
|
-
*
|
|
4
|
-
* Export showcase page for MVP consumers.
|
|
5
|
-
*
|
|
6
|
-
* Usage:
|
|
7
|
-
* ```typescript
|
|
8
|
-
* // app/showcase/page.tsx
|
|
9
|
-
* export { ShowcasePage as default } from '@payez/next-mvp/pages/showcase';
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export { ShowcasePage, ShowcasePage as default } from './ShowcasePage';
|
|
1
|
+
/**
|
|
2
|
+
* Feature Showcase Page
|
|
3
|
+
*
|
|
4
|
+
* Export showcase page for MVP consumers.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // app/showcase/page.tsx
|
|
9
|
+
* export { ShowcasePage as default } from '@payez/next-mvp/pages/showcase';
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export { ShowcasePage, ShowcasePage as default } from './ShowcasePage';
|
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { authClient } from '../../client/better-auth-client';
|
|
4
|
-
import { useState, useEffect } from 'react';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Emergency Logout Page
|
|
8
|
-
*
|
|
9
|
-
* Nuclear option for clearing auth state when things go wrong.
|
|
10
|
-
* Clears cookies, localStorage, and forces NextAuth signout.
|
|
11
|
-
*
|
|
12
|
-
* Usage in consuming app:
|
|
13
|
-
* ```typescript
|
|
14
|
-
* // app/test-env/emergency-logout/page.tsx
|
|
15
|
-
* export { EmergencyLogoutPage as default } from '@payez/next-mvp/pages/test-env';
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export function EmergencyLogoutPage() {
|
|
19
|
-
const { data: sessionData, isPending } = authClient.useSession();
|
|
20
|
-
const status = isPending ? 'loading' : sessionData ? 'authenticated' : 'unauthenticated';
|
|
21
|
-
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
22
|
-
const [isLoggingOut, setIsLoggingOut] = useState(false);
|
|
23
|
-
const [logoutComplete, setLogoutComplete] = useState(false);
|
|
24
|
-
const [logs, setLogs] = useState<string[]>([]);
|
|
25
|
-
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
const checkDarkMode = () => {
|
|
28
|
-
const isDark = document.documentElement.classList.contains('dark') ||
|
|
29
|
-
window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
30
|
-
setIsDarkMode(isDark);
|
|
31
|
-
};
|
|
32
|
-
checkDarkMode();
|
|
33
|
-
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
34
|
-
mediaQuery.addEventListener('change', checkDarkMode);
|
|
35
|
-
return () => mediaQuery.removeEventListener('change', checkDarkMode);
|
|
36
|
-
}, []);
|
|
37
|
-
|
|
38
|
-
const addLog = (message: string) => {
|
|
39
|
-
setLogs(prev => [...prev, `[${new Date().toISOString().substring(11, 19)}] ${message}`]);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const handleEmergencyLogout = async () => {
|
|
43
|
-
setIsLoggingOut(true);
|
|
44
|
-
setLogs([]);
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
// Step 1: Clear all cookies
|
|
48
|
-
addLog('Clearing cookies...');
|
|
49
|
-
document.cookie.split(';').forEach(cookie => {
|
|
50
|
-
const name = cookie.split('=')[0].trim();
|
|
51
|
-
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/`;
|
|
52
|
-
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=${window.location.hostname}`;
|
|
53
|
-
});
|
|
54
|
-
addLog('Cookies cleared');
|
|
55
|
-
|
|
56
|
-
// Step 2: Clear localStorage
|
|
57
|
-
addLog('Clearing localStorage...');
|
|
58
|
-
const keysToRemove: string[] = [];
|
|
59
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
60
|
-
const key = localStorage.key(i);
|
|
61
|
-
if (key) keysToRemove.push(key);
|
|
62
|
-
}
|
|
63
|
-
keysToRemove.forEach(key => {
|
|
64
|
-
localStorage.removeItem(key);
|
|
65
|
-
addLog(` Removed: ${key}`);
|
|
66
|
-
});
|
|
67
|
-
addLog(`localStorage cleared (${keysToRemove.length} items)`);
|
|
68
|
-
|
|
69
|
-
// Step 3: Clear sessionStorage
|
|
70
|
-
addLog('Clearing sessionStorage...');
|
|
71
|
-
sessionStorage.clear();
|
|
72
|
-
addLog('sessionStorage cleared');
|
|
73
|
-
|
|
74
|
-
// Step 4: Call Better Auth signOut
|
|
75
|
-
addLog('Calling Better Auth signOut...');
|
|
76
|
-
await authClient.signOut();
|
|
77
|
-
addLog('Better Auth signOut complete');
|
|
78
|
-
|
|
79
|
-
// Step 5: Clear any auth-related fetch cache
|
|
80
|
-
addLog('Invalidating caches...');
|
|
81
|
-
if ('caches' in window) {
|
|
82
|
-
const cacheNames = await caches.keys();
|
|
83
|
-
await Promise.all(cacheNames.map(name => caches.delete(name)));
|
|
84
|
-
addLog(`Cleared ${cacheNames.length} caches`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
addLog('Emergency logout complete!');
|
|
88
|
-
setLogoutComplete(true);
|
|
89
|
-
|
|
90
|
-
} catch (error) {
|
|
91
|
-
addLog(`ERROR: ${error instanceof Error ? error.message : String(error)}`);
|
|
92
|
-
} finally {
|
|
93
|
-
setIsLoggingOut(false);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const handleRedirectHome = () => {
|
|
98
|
-
window.location.href = '/';
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
return (
|
|
102
|
-
<div className={`min-h-screen p-8 ${isDarkMode ? 'bg-slate-950 text-white' : 'bg-gray-50 text-gray-900'}`}>
|
|
103
|
-
<div className="max-w-2xl mx-auto">
|
|
104
|
-
<h1 className="text-2xl font-bold mb-2">Emergency Logout</h1>
|
|
105
|
-
<p className={`mb-6 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`}>
|
|
106
|
-
Nuclear option for when auth gets into a bad state. Clears everything.
|
|
107
|
-
</p>
|
|
108
|
-
|
|
109
|
-
{/* Current Status */}
|
|
110
|
-
<div className={`mb-6 p-4 rounded-lg ${isDarkMode ? 'bg-slate-900' : 'bg-white border'}`}>
|
|
111
|
-
<h2 className="font-semibold mb-2">Current Status</h2>
|
|
112
|
-
<div className="flex items-center gap-2">
|
|
113
|
-
<span className={`inline-block w-3 h-3 rounded-full ${
|
|
114
|
-
status === 'authenticated' ? 'bg-green-500' :
|
|
115
|
-
status === 'loading' ? 'bg-yellow-500' : 'bg-red-500'
|
|
116
|
-
}`} />
|
|
117
|
-
<span className="capitalize">{status}</span>
|
|
118
|
-
</div>
|
|
119
|
-
</div>
|
|
120
|
-
|
|
121
|
-
{/* Action Button */}
|
|
122
|
-
{!logoutComplete ? (
|
|
123
|
-
<button
|
|
124
|
-
onClick={handleEmergencyLogout}
|
|
125
|
-
disabled={isLoggingOut}
|
|
126
|
-
className={`w-full py-3 px-4 rounded-lg font-semibold transition-colors ${
|
|
127
|
-
isLoggingOut
|
|
128
|
-
? 'bg-gray-500 cursor-not-allowed'
|
|
129
|
-
: 'bg-red-600 hover:bg-red-700 text-white'
|
|
130
|
-
}`}
|
|
131
|
-
>
|
|
132
|
-
{isLoggingOut ? 'Logging out...' : 'Emergency Logout'}
|
|
133
|
-
</button>
|
|
134
|
-
) : (
|
|
135
|
-
<div className="space-y-3">
|
|
136
|
-
<div className={`p-4 rounded-lg ${isDarkMode ? 'bg-green-900/30 border border-green-700' : 'bg-green-50 border border-green-200'}`}>
|
|
137
|
-
<p className={`font-semibold ${isDarkMode ? 'text-green-400' : 'text-green-700'}`}>
|
|
138
|
-
Logout complete! All auth state has been cleared.
|
|
139
|
-
</p>
|
|
140
|
-
</div>
|
|
141
|
-
<button
|
|
142
|
-
onClick={handleRedirectHome}
|
|
143
|
-
className="w-full py-3 px-4 rounded-lg font-semibold bg-blue-600 hover:bg-blue-700 text-white transition-colors"
|
|
144
|
-
>
|
|
145
|
-
Go to Home Page
|
|
146
|
-
</button>
|
|
147
|
-
</div>
|
|
148
|
-
)}
|
|
149
|
-
|
|
150
|
-
{/* Log Output */}
|
|
151
|
-
{logs.length > 0 && (
|
|
152
|
-
<div className={`mt-6 p-4 rounded-lg font-mono text-sm ${isDarkMode ? 'bg-slate-900' : 'bg-gray-100'}`}>
|
|
153
|
-
<h3 className="font-semibold mb-2">Log</h3>
|
|
154
|
-
<div className="space-y-1">
|
|
155
|
-
{logs.map((log, i) => (
|
|
156
|
-
<div key={i} className={log.includes('ERROR') ? 'text-red-500' : isDarkMode ? 'text-gray-300' : 'text-gray-700'}>
|
|
157
|
-
{log}
|
|
158
|
-
</div>
|
|
159
|
-
))}
|
|
160
|
-
</div>
|
|
161
|
-
</div>
|
|
162
|
-
)}
|
|
163
|
-
|
|
164
|
-
{/* What this does */}
|
|
165
|
-
<div className={`mt-8 p-4 rounded-lg ${isDarkMode ? 'bg-slate-900' : 'bg-white border'}`}>
|
|
166
|
-
<h2 className="font-semibold mb-2">What this does</h2>
|
|
167
|
-
<ul className={`list-disc list-inside space-y-1 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`}>
|
|
168
|
-
<li>Clears all browser cookies</li>
|
|
169
|
-
<li>Clears localStorage (theme, preferences, etc.)</li>
|
|
170
|
-
<li>Clears sessionStorage</li>
|
|
171
|
-
<li>Calls NextAuth signOut</li>
|
|
172
|
-
<li>Invalidates browser caches</li>
|
|
173
|
-
</ul>
|
|
174
|
-
</div>
|
|
175
|
-
</div>
|
|
176
|
-
</div>
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export default EmergencyLogoutPage;
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { authClient } from '../../client/better-auth-client';
|
|
4
|
+
import { useState, useEffect } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Emergency Logout Page
|
|
8
|
+
*
|
|
9
|
+
* Nuclear option for clearing auth state when things go wrong.
|
|
10
|
+
* Clears cookies, localStorage, and forces NextAuth signout.
|
|
11
|
+
*
|
|
12
|
+
* Usage in consuming app:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // app/test-env/emergency-logout/page.tsx
|
|
15
|
+
* export { EmergencyLogoutPage as default } from '@payez/next-mvp/pages/test-env';
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function EmergencyLogoutPage() {
|
|
19
|
+
const { data: sessionData, isPending } = authClient.useSession();
|
|
20
|
+
const status = isPending ? 'loading' : sessionData ? 'authenticated' : 'unauthenticated';
|
|
21
|
+
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
22
|
+
const [isLoggingOut, setIsLoggingOut] = useState(false);
|
|
23
|
+
const [logoutComplete, setLogoutComplete] = useState(false);
|
|
24
|
+
const [logs, setLogs] = useState<string[]>([]);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const checkDarkMode = () => {
|
|
28
|
+
const isDark = document.documentElement.classList.contains('dark') ||
|
|
29
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
30
|
+
setIsDarkMode(isDark);
|
|
31
|
+
};
|
|
32
|
+
checkDarkMode();
|
|
33
|
+
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
34
|
+
mediaQuery.addEventListener('change', checkDarkMode);
|
|
35
|
+
return () => mediaQuery.removeEventListener('change', checkDarkMode);
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
const addLog = (message: string) => {
|
|
39
|
+
setLogs(prev => [...prev, `[${new Date().toISOString().substring(11, 19)}] ${message}`]);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const handleEmergencyLogout = async () => {
|
|
43
|
+
setIsLoggingOut(true);
|
|
44
|
+
setLogs([]);
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
// Step 1: Clear all cookies
|
|
48
|
+
addLog('Clearing cookies...');
|
|
49
|
+
document.cookie.split(';').forEach(cookie => {
|
|
50
|
+
const name = cookie.split('=')[0].trim();
|
|
51
|
+
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/`;
|
|
52
|
+
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=${window.location.hostname}`;
|
|
53
|
+
});
|
|
54
|
+
addLog('Cookies cleared');
|
|
55
|
+
|
|
56
|
+
// Step 2: Clear localStorage
|
|
57
|
+
addLog('Clearing localStorage...');
|
|
58
|
+
const keysToRemove: string[] = [];
|
|
59
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
60
|
+
const key = localStorage.key(i);
|
|
61
|
+
if (key) keysToRemove.push(key);
|
|
62
|
+
}
|
|
63
|
+
keysToRemove.forEach(key => {
|
|
64
|
+
localStorage.removeItem(key);
|
|
65
|
+
addLog(` Removed: ${key}`);
|
|
66
|
+
});
|
|
67
|
+
addLog(`localStorage cleared (${keysToRemove.length} items)`);
|
|
68
|
+
|
|
69
|
+
// Step 3: Clear sessionStorage
|
|
70
|
+
addLog('Clearing sessionStorage...');
|
|
71
|
+
sessionStorage.clear();
|
|
72
|
+
addLog('sessionStorage cleared');
|
|
73
|
+
|
|
74
|
+
// Step 4: Call Better Auth signOut
|
|
75
|
+
addLog('Calling Better Auth signOut...');
|
|
76
|
+
await authClient.signOut();
|
|
77
|
+
addLog('Better Auth signOut complete');
|
|
78
|
+
|
|
79
|
+
// Step 5: Clear any auth-related fetch cache
|
|
80
|
+
addLog('Invalidating caches...');
|
|
81
|
+
if ('caches' in window) {
|
|
82
|
+
const cacheNames = await caches.keys();
|
|
83
|
+
await Promise.all(cacheNames.map(name => caches.delete(name)));
|
|
84
|
+
addLog(`Cleared ${cacheNames.length} caches`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
addLog('Emergency logout complete!');
|
|
88
|
+
setLogoutComplete(true);
|
|
89
|
+
|
|
90
|
+
} catch (error) {
|
|
91
|
+
addLog(`ERROR: ${error instanceof Error ? error.message : String(error)}`);
|
|
92
|
+
} finally {
|
|
93
|
+
setIsLoggingOut(false);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const handleRedirectHome = () => {
|
|
98
|
+
window.location.href = '/';
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<div className={`min-h-screen p-8 ${isDarkMode ? 'bg-slate-950 text-white' : 'bg-gray-50 text-gray-900'}`}>
|
|
103
|
+
<div className="max-w-2xl mx-auto">
|
|
104
|
+
<h1 className="text-2xl font-bold mb-2">Emergency Logout</h1>
|
|
105
|
+
<p className={`mb-6 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`}>
|
|
106
|
+
Nuclear option for when auth gets into a bad state. Clears everything.
|
|
107
|
+
</p>
|
|
108
|
+
|
|
109
|
+
{/* Current Status */}
|
|
110
|
+
<div className={`mb-6 p-4 rounded-lg ${isDarkMode ? 'bg-slate-900' : 'bg-white border'}`}>
|
|
111
|
+
<h2 className="font-semibold mb-2">Current Status</h2>
|
|
112
|
+
<div className="flex items-center gap-2">
|
|
113
|
+
<span className={`inline-block w-3 h-3 rounded-full ${
|
|
114
|
+
status === 'authenticated' ? 'bg-green-500' :
|
|
115
|
+
status === 'loading' ? 'bg-yellow-500' : 'bg-red-500'
|
|
116
|
+
}`} />
|
|
117
|
+
<span className="capitalize">{status}</span>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
{/* Action Button */}
|
|
122
|
+
{!logoutComplete ? (
|
|
123
|
+
<button
|
|
124
|
+
onClick={handleEmergencyLogout}
|
|
125
|
+
disabled={isLoggingOut}
|
|
126
|
+
className={`w-full py-3 px-4 rounded-lg font-semibold transition-colors ${
|
|
127
|
+
isLoggingOut
|
|
128
|
+
? 'bg-gray-500 cursor-not-allowed'
|
|
129
|
+
: 'bg-red-600 hover:bg-red-700 text-white'
|
|
130
|
+
}`}
|
|
131
|
+
>
|
|
132
|
+
{isLoggingOut ? 'Logging out...' : 'Emergency Logout'}
|
|
133
|
+
</button>
|
|
134
|
+
) : (
|
|
135
|
+
<div className="space-y-3">
|
|
136
|
+
<div className={`p-4 rounded-lg ${isDarkMode ? 'bg-green-900/30 border border-green-700' : 'bg-green-50 border border-green-200'}`}>
|
|
137
|
+
<p className={`font-semibold ${isDarkMode ? 'text-green-400' : 'text-green-700'}`}>
|
|
138
|
+
Logout complete! All auth state has been cleared.
|
|
139
|
+
</p>
|
|
140
|
+
</div>
|
|
141
|
+
<button
|
|
142
|
+
onClick={handleRedirectHome}
|
|
143
|
+
className="w-full py-3 px-4 rounded-lg font-semibold bg-blue-600 hover:bg-blue-700 text-white transition-colors"
|
|
144
|
+
>
|
|
145
|
+
Go to Home Page
|
|
146
|
+
</button>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
|
|
150
|
+
{/* Log Output */}
|
|
151
|
+
{logs.length > 0 && (
|
|
152
|
+
<div className={`mt-6 p-4 rounded-lg font-mono text-sm ${isDarkMode ? 'bg-slate-900' : 'bg-gray-100'}`}>
|
|
153
|
+
<h3 className="font-semibold mb-2">Log</h3>
|
|
154
|
+
<div className="space-y-1">
|
|
155
|
+
{logs.map((log, i) => (
|
|
156
|
+
<div key={i} className={log.includes('ERROR') ? 'text-red-500' : isDarkMode ? 'text-gray-300' : 'text-gray-700'}>
|
|
157
|
+
{log}
|
|
158
|
+
</div>
|
|
159
|
+
))}
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
)}
|
|
163
|
+
|
|
164
|
+
{/* What this does */}
|
|
165
|
+
<div className={`mt-8 p-4 rounded-lg ${isDarkMode ? 'bg-slate-900' : 'bg-white border'}`}>
|
|
166
|
+
<h2 className="font-semibold mb-2">What this does</h2>
|
|
167
|
+
<ul className={`list-disc list-inside space-y-1 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`}>
|
|
168
|
+
<li>Clears all browser cookies</li>
|
|
169
|
+
<li>Clears localStorage (theme, preferences, etc.)</li>
|
|
170
|
+
<li>Clears sessionStorage</li>
|
|
171
|
+
<li>Calls NextAuth signOut</li>
|
|
172
|
+
<li>Invalidates browser caches</li>
|
|
173
|
+
</ul>
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export default EmergencyLogoutPage;
|