@payez/next-mvp 3.9.1 → 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.
Files changed (147) hide show
  1. package/dist/api/auth-handler.d.ts +1 -2
  2. package/dist/api/auth-handler.js +9 -9
  3. package/dist/api-handlers/account/change-password.js +110 -112
  4. package/dist/api-handlers/admin/analytics.d.ts +19 -20
  5. package/dist/api-handlers/admin/analytics.js +378 -379
  6. package/dist/api-handlers/admin/audit.d.ts +19 -20
  7. package/dist/api-handlers/admin/audit.js +213 -214
  8. package/dist/api-handlers/admin/index.d.ts +21 -22
  9. package/dist/api-handlers/admin/index.js +42 -43
  10. package/dist/api-handlers/admin/redis-sessions.d.ts +35 -36
  11. package/dist/api-handlers/admin/redis-sessions.js +203 -204
  12. package/dist/api-handlers/admin/sessions.d.ts +20 -21
  13. package/dist/api-handlers/admin/sessions.js +283 -284
  14. package/dist/api-handlers/admin/site-logs.d.ts +45 -46
  15. package/dist/api-handlers/admin/site-logs.js +317 -318
  16. package/dist/api-handlers/admin/stats.d.ts +20 -21
  17. package/dist/api-handlers/admin/stats.js +239 -240
  18. package/dist/api-handlers/admin/users.d.ts +19 -20
  19. package/dist/api-handlers/admin/users.js +221 -222
  20. package/dist/api-handlers/admin/vibe-data.d.ts +79 -80
  21. package/dist/api-handlers/admin/vibe-data.js +267 -268
  22. package/dist/api-handlers/auth/refresh.js +633 -635
  23. package/dist/api-handlers/auth/signout.js +186 -187
  24. package/dist/api-handlers/auth/status.js +4 -7
  25. package/dist/api-handlers/auth/update-session.d.ts +1 -1
  26. package/dist/api-handlers/auth/update-session.js +12 -14
  27. package/dist/api-handlers/auth/verify-code.d.ts +43 -43
  28. package/dist/api-handlers/auth/verify-code.js +90 -94
  29. package/dist/api-handlers/session/viability.js +114 -146
  30. package/dist/api-handlers/test/force-expire.js +59 -65
  31. package/dist/auth/auth-decision.js +182 -182
  32. package/dist/auth/better-auth.d.ts +3 -6
  33. package/dist/auth/better-auth.js +3 -6
  34. package/dist/auth/route-config.js +2 -2
  35. package/dist/auth/utils/token-utils.d.ts +83 -84
  36. package/dist/auth/utils/token-utils.js +218 -219
  37. package/dist/client/AuthContext.js +115 -112
  38. package/dist/client/better-auth-client.d.ts +1020 -1020
  39. package/dist/client/fetch-with-auth.js +2 -2
  40. package/dist/components/SessionSync.js +121 -119
  41. package/dist/components/account/MobileNavDrawer.js +64 -64
  42. package/dist/components/account/UserAvatarMenu.js +91 -88
  43. package/dist/components/admin/VibeAdminLayout.js +71 -69
  44. package/dist/hooks/useAuth.js +9 -7
  45. package/dist/hooks/useAuthSettings.js +93 -93
  46. package/dist/hooks/useAvailableProviders.d.ts +43 -45
  47. package/dist/hooks/useAvailableProviders.js +112 -108
  48. package/dist/hooks/useSessionExpiration.d.ts +2 -3
  49. package/dist/hooks/useSessionExpiration.js +2 -2
  50. package/dist/hooks/useViabilitySession.js +3 -2
  51. package/dist/index.js +4 -6
  52. package/dist/lib/app-slug.d.ts +95 -95
  53. package/dist/lib/app-slug.js +172 -172
  54. package/dist/lib/standardized-client-api.js +10 -5
  55. package/dist/lib/startup-init.js +21 -25
  56. package/dist/lib/test-aware-get-token.js +86 -81
  57. package/dist/lib/token-lifecycle.d.ts +78 -52
  58. package/dist/lib/token-lifecycle.js +360 -398
  59. package/dist/pages/admin-login/page.js +73 -83
  60. package/dist/pages/client-admin/ClientSiteAdminPage.js +179 -177
  61. package/dist/pages/login/page.js +202 -211
  62. package/dist/pages/showcase/ShowcasePage.js +142 -140
  63. package/dist/pages/test-env/EmergencyLogoutPage.js +99 -98
  64. package/dist/pages/test-env/JwtInspectPage.js +116 -114
  65. package/dist/pages/test-env/RefreshTokenPage.js +4 -2
  66. package/dist/pages/test-env/TestEnvPage.js +51 -49
  67. package/dist/pages/verify-code/page.js +412 -408
  68. package/dist/routes/auth/logout.d.ts +31 -31
  69. package/dist/routes/auth/logout.js +98 -113
  70. package/dist/routes/auth/nextauth.d.ts +14 -11
  71. package/dist/routes/auth/nextauth.js +25 -57
  72. package/dist/routes/auth/session.js +157 -179
  73. package/dist/routes/auth/viability.js +190 -201
  74. package/dist/server/auth.d.ts +50 -0
  75. package/dist/server/auth.js +62 -0
  76. package/dist/stores/authStore.js +19 -23
  77. package/dist/utils/logout.js +5 -5
  78. package/package.json +1 -3
  79. package/src/api/auth-handler.ts +550 -549
  80. package/src/api-handlers/account/change-password.ts +5 -8
  81. package/src/api-handlers/admin/analytics.ts +4 -6
  82. package/src/api-handlers/admin/audit.ts +5 -7
  83. package/src/api-handlers/admin/index.ts +1 -2
  84. package/src/api-handlers/admin/redis-sessions.ts +6 -8
  85. package/src/api-handlers/admin/sessions.ts +5 -7
  86. package/src/api-handlers/admin/site-logs.ts +8 -10
  87. package/src/api-handlers/admin/stats.ts +4 -6
  88. package/src/api-handlers/admin/users.ts +5 -7
  89. package/src/api-handlers/admin/vibe-data.ts +10 -12
  90. package/src/api-handlers/auth/refresh.ts +5 -7
  91. package/src/api-handlers/auth/signout.ts +5 -6
  92. package/src/api-handlers/auth/status.ts +4 -7
  93. package/src/api-handlers/auth/update-session.ts +123 -125
  94. package/src/api-handlers/auth/verify-code.ts +9 -13
  95. package/src/api-handlers/session/viability.ts +10 -47
  96. package/src/api-handlers/test/force-expire.ts +4 -11
  97. package/src/auth/auth-decision.ts +1 -1
  98. package/src/auth/better-auth.ts +138 -141
  99. package/src/auth/route-config.ts +219 -219
  100. package/src/auth/utils/token-utils.ts +0 -1
  101. package/src/client/AuthContext.tsx +6 -2
  102. package/src/client/fetch-with-auth.ts +47 -47
  103. package/src/components/SessionSync.tsx +6 -5
  104. package/src/components/account/MobileNavDrawer.tsx +3 -3
  105. package/src/components/account/UserAvatarMenu.tsx +6 -3
  106. package/src/components/admin/VibeAdminLayout.tsx +4 -2
  107. package/src/config/logger.ts +1 -1
  108. package/src/hooks/useAuth.ts +117 -115
  109. package/src/hooks/useAuthSettings.ts +2 -2
  110. package/src/hooks/useAvailableProviders.ts +9 -5
  111. package/src/hooks/useSessionExpiration.ts +101 -102
  112. package/src/hooks/useViabilitySession.ts +336 -335
  113. package/src/index.ts +60 -63
  114. package/src/lib/api-handler.ts +0 -1
  115. package/src/lib/app-slug.ts +6 -6
  116. package/src/lib/standardized-client-api.ts +901 -895
  117. package/src/lib/startup-init.ts +243 -247
  118. package/src/lib/test-aware-get-token.ts +22 -12
  119. package/src/lib/token-lifecycle.ts +12 -53
  120. package/src/pages/admin-login/page.tsx +9 -17
  121. package/src/pages/client-admin/ClientSiteAdminPage.tsx +4 -2
  122. package/src/pages/login/page.tsx +21 -28
  123. package/src/pages/showcase/ShowcasePage.tsx +4 -2
  124. package/src/pages/test-env/EmergencyLogoutPage.tsx +7 -6
  125. package/src/pages/test-env/JwtInspectPage.tsx +5 -3
  126. package/src/pages/test-env/RefreshTokenPage.tsx +157 -155
  127. package/src/pages/test-env/TestEnvPage.tsx +4 -2
  128. package/src/pages/verify-code/page.tsx +10 -6
  129. package/src/routes/auth/logout.ts +7 -25
  130. package/src/routes/auth/nextauth.ts +45 -71
  131. package/src/routes/auth/session.ts +25 -50
  132. package/src/routes/auth/viability.ts +7 -19
  133. package/src/server/auth.ts +60 -0
  134. package/src/stores/authStore.ts +1899 -1904
  135. package/src/utils/logout.ts +30 -30
  136. package/src/auth/auth-options.ts +0 -237
  137. package/src/auth/callbacks/index.ts +0 -7
  138. package/src/auth/callbacks/jwt.ts +0 -382
  139. package/src/auth/callbacks/session.ts +0 -243
  140. package/src/auth/callbacks/signin.ts +0 -56
  141. package/src/auth/events/index.ts +0 -5
  142. package/src/auth/events/signout.ts +0 -33
  143. package/src/auth/providers/credentials.ts +0 -256
  144. package/src/auth/providers/index.ts +0 -6
  145. package/src/auth/providers/oauth.ts +0 -114
  146. package/src/lib/nextauth-secret.ts +0 -121
  147. package/src/types/next-auth.d.ts +0 -15
@@ -1,140 +1,142 @@
1
- "use strict";
2
- 'use client';
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ShowcasePage = ShowcasePage;
8
- const jsx_runtime_1 = require("react/jsx-runtime");
9
- const react_1 = require("next-auth/react");
10
- const react_2 = require("react");
11
- const link_1 = __importDefault(require("next/link"));
12
- // Shared dark mode hook to avoid duplication
13
- function useDarkMode() {
14
- const [isDarkMode, setIsDarkMode] = (0, react_2.useState)(false);
15
- (0, react_2.useEffect)(() => {
16
- const checkDarkMode = () => {
17
- const isDark = document.documentElement.classList.contains('dark') ||
18
- window.matchMedia('(prefers-color-scheme: dark)').matches;
19
- setIsDarkMode(isDark);
20
- };
21
- checkDarkMode();
22
- const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
23
- mediaQuery.addEventListener('change', checkDarkMode);
24
- return () => mediaQuery.removeEventListener('change', checkDarkMode);
25
- }, []);
26
- return isDarkMode;
27
- }
28
- function FeatureCard({ title, description, status, link, children }) {
29
- const isDarkMode = useDarkMode();
30
- const content = ((0, jsx_runtime_1.jsxs)("div", { className: `p-6 rounded-lg h-full ${isDarkMode
31
- ? 'bg-slate-900 border border-slate-700'
32
- : 'bg-white border border-gray-200'}`, children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-start justify-between mb-3", children: [(0, jsx_runtime_1.jsx)("h3", { className: "font-semibold text-lg", children: title }), status === 'coming-soon' && ((0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded-full ${isDarkMode ? 'bg-amber-900/50 text-amber-400' : 'bg-amber-100 text-amber-700'}`, children: "Coming Soon" }))] }), (0, jsx_runtime_1.jsx)("p", { className: `text-sm mb-4 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`, children: description }), children] }));
33
- if (link && status === 'available') {
34
- return ((0, jsx_runtime_1.jsx)(link_1.default, { href: link, className: "block hover:opacity-90 transition-opacity", children: content }));
35
- }
36
- return content;
37
- }
38
- function DemoButton({ variant, children, onClick }) {
39
- const variants = {
40
- primary: 'bg-blue-600 hover:bg-blue-700 text-white',
41
- secondary: 'bg-gray-200 hover:bg-gray-300 text-gray-800 dark:bg-slate-700 dark:hover:bg-slate-600 dark:text-white',
42
- danger: 'bg-red-600 hover:bg-red-700 text-white',
43
- };
44
- return ((0, jsx_runtime_1.jsx)("button", { onClick: onClick, className: `px-4 py-2 rounded-lg text-sm font-medium transition-colors ${variants[variant]}`, children: children }));
45
- }
46
- /**
47
- * Feature Showcase Page
48
- *
49
- * Demonstrates MVP capabilities with interactive examples.
50
- *
51
- * Usage in consuming app:
52
- * ```typescript
53
- * // app/showcase/page.tsx
54
- * export { ShowcasePage as default } from '@payez/next-mvp/pages/showcase';
55
- * ```
56
- */
57
- function ShowcasePage() {
58
- const { data: session, status } = (0, react_1.useSession)();
59
- const isDarkMode = useDarkMode();
60
- const [toastVisible, setToastVisible] = (0, react_2.useState)(false);
61
- const [toastMessage, setToastMessage] = (0, react_2.useState)('');
62
- const [modalVisible, setModalVisible] = (0, react_2.useState)(false);
63
- const toastTimeoutRef = (0, react_2.useRef)(null);
64
- const modalRef = (0, react_2.useRef)(null);
65
- const previousFocusRef = (0, react_2.useRef)(null);
66
- // Type the extended session properly
67
- const extSession = session;
68
- // Toast with proper cleanup to prevent race conditions
69
- const showToast = (0, react_2.useCallback)((message) => {
70
- if (toastTimeoutRef.current) {
71
- clearTimeout(toastTimeoutRef.current);
72
- }
73
- setToastMessage(message);
74
- setToastVisible(true);
75
- toastTimeoutRef.current = setTimeout(() => setToastVisible(false), 3000);
76
- }, []);
77
- // Cleanup toast timeout on unmount
78
- (0, react_2.useEffect)(() => {
79
- return () => {
80
- if (toastTimeoutRef.current) {
81
- clearTimeout(toastTimeoutRef.current);
82
- }
83
- };
84
- }, []);
85
- // Modal focus trap and keyboard handling
86
- (0, react_2.useEffect)(() => {
87
- if (!modalVisible)
88
- return;
89
- // Store previous focus
90
- previousFocusRef.current = document.activeElement;
91
- // Focus the modal
92
- modalRef.current?.focus();
93
- // Handle Escape key
94
- const handleKeyDown = (e) => {
95
- if (e.key === 'Escape') {
96
- setModalVisible(false);
97
- }
98
- // Focus trap
99
- if (e.key === 'Tab' && modalRef.current) {
100
- const focusableElements = modalRef.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
101
- const firstElement = focusableElements[0];
102
- const lastElement = focusableElements[focusableElements.length - 1];
103
- if (e.shiftKey && document.activeElement === firstElement) {
104
- e.preventDefault();
105
- lastElement?.focus();
106
- }
107
- else if (!e.shiftKey && document.activeElement === lastElement) {
108
- e.preventDefault();
109
- firstElement?.focus();
110
- }
111
- }
112
- };
113
- document.addEventListener('keydown', handleKeyDown);
114
- return () => {
115
- document.removeEventListener('keydown', handleKeyDown);
116
- // Restore focus when modal closes
117
- previousFocusRef.current?.focus();
118
- };
119
- }, [modalVisible]);
120
- // Get status text for screen readers
121
- const getStatusText = () => {
122
- if (status === 'authenticated')
123
- return 'Authenticated';
124
- if (status === 'loading')
125
- return 'Loading';
126
- return 'Not authenticated';
127
- };
128
- return ((0, jsx_runtime_1.jsxs)("div", { className: `min-h-screen p-8 ${isDarkMode ? 'bg-slate-950 text-white' : 'bg-gray-50 text-gray-900'}`, children: [(0, jsx_runtime_1.jsxs)("div", { className: "max-w-6xl mx-auto", children: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-8", children: [(0, jsx_runtime_1.jsx)("h1", { className: "text-3xl font-bold mb-2", children: "MVP Feature Showcase" }), (0, jsx_runtime_1.jsx)("p", { className: `${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`, children: "Interactive demonstrations of @payez/next-mvp capabilities" })] }), (0, jsx_runtime_1.jsxs)("div", { className: `mb-8 p-4 rounded-lg flex items-center justify-between ${isDarkMode ? 'bg-slate-900 border border-slate-700' : 'bg-white border'}`, children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-4", children: [(0, jsx_runtime_1.jsx)("div", { className: `w-3 h-3 rounded-full ${status === 'authenticated' ? 'bg-green-500' :
129
- status === 'loading' ? 'bg-yellow-500' : 'bg-red-500'}`, "aria-hidden": "true" }), (0, jsx_runtime_1.jsx)("span", { className: "sr-only", children: getStatusText() }), (0, jsx_runtime_1.jsx)("span", { className: "font-medium", children: status === 'authenticated' ? `Logged in as ${session?.user?.email}` :
130
- status === 'loading' ? 'Loading session...' : 'Not authenticated' })] }), status === 'unauthenticated' && ((0, jsx_runtime_1.jsx)(link_1.default, { href: "/account-auth/login", className: "text-blue-500 hover:text-blue-600 text-sm font-medium", children: "Sign in to test authenticated features" }))] }), (0, jsx_runtime_1.jsxs)("div", { className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8", children: [(0, jsx_runtime_1.jsx)(FeatureCard, { title: "Authentication", description: "Complete auth flow with traditional login, OAuth providers, and password recovery.", status: "available", link: "/account-auth/login", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Email/Password" }), (0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "OAuth" }), (0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "2FA" })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Role-Based Access Control", description: "Fine-grained permissions with roles and access control configuration.", status: "available", children: (0, jsx_runtime_1.jsx)("div", { className: `text-xs p-3 rounded font-mono ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: extSession?.user?.roles ?
131
- `Roles: ${extSession.user.roles.join(', ')}` :
132
- 'Sign in to view roles' }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Toast Notifications", description: "Non-blocking notifications for user feedback and status updates.", status: "available", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex gap-2", children: [(0, jsx_runtime_1.jsx)(DemoButton, { variant: "primary", onClick: () => showToast('Success! Action completed.'), children: "Success" }), (0, jsx_runtime_1.jsx)(DemoButton, { variant: "danger", onClick: () => showToast('Error! Something went wrong.'), children: "Error" })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Modal Dialogs", description: "Accessible modal dialogs for confirmations and focused interactions.", status: "available", children: (0, jsx_runtime_1.jsx)(DemoButton, { variant: "secondary", onClick: () => setModalVisible(true), children: "Open Modal" }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Form Validation", description: "Client and server-side validation with real-time feedback and error handling.", status: "available", link: "/account-auth/recovery", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Real-time" }), (0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Password Rules" })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Session Management", description: "JWT-based sessions with automatic refresh and secure token handling.", status: "available", link: "/test-env", children: (0, jsx_runtime_1.jsxs)("div", { className: "space-y-1 text-xs", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex justify-between", children: [(0, jsx_runtime_1.jsx)("span", { children: "Access Token:" }), (0, jsx_runtime_1.jsx)("span", { className: extSession?.accessToken ? 'text-green-500' : 'text-red-500', children: extSession?.accessToken ? 'Valid' : 'None' })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex justify-between", children: [(0, jsx_runtime_1.jsx)("span", { children: "Refresh Token:" }), (0, jsx_runtime_1.jsx)("span", { className: extSession?.refreshToken ? 'text-green-500' : 'text-red-500', children: extSession?.refreshToken ? 'Valid' : 'None' })] })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "User Profile", description: "Profile management with avatar, display name, and account settings.", status: "available", link: "/profile", children: (0, jsx_runtime_1.jsxs)("div", { className: `flex items-center gap-3 p-2 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: [(0, jsx_runtime_1.jsx)("div", { className: "w-10 h-10 rounded-full bg-blue-500 flex items-center justify-center text-white font-medium", children: session?.user?.email?.charAt(0).toUpperCase() || '?' }), (0, jsx_runtime_1.jsx)("div", { className: "text-sm truncate", children: session?.user?.email || 'Not signed in' })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Security Settings", description: "Password management, 2FA configuration, and active session control.", status: "available", link: "/security", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Change Password" }), (0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "2FA Setup" })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Theme Support", description: "Light and dark mode with system preference detection and manual toggle.", status: "available", children: (0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-3", children: (0, jsx_runtime_1.jsxs)("div", { className: `px-3 py-2 rounded text-sm ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: ["Current: ", isDarkMode ? 'Dark' : 'Light'] }) }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Admin Panel", description: "Built-in admin interface for user management, roles, and system configuration.", status: "coming-soon", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "User Management" }), (0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Schema Browser" })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Data Tables", description: "Sortable, filterable, paginated tables with column customization.", status: "coming-soon", children: (0, jsx_runtime_1.jsx)("div", { className: `text-xs p-3 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Sort, filter, paginate, export" }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "API Client", description: "Type-safe API client with automatic auth headers and error handling.", status: "available", children: (0, jsx_runtime_1.jsx)("div", { className: `text-xs p-3 rounded font-mono ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "fetchWithSession(url, options)" }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: `p-6 rounded-lg ${isDarkMode ? 'bg-slate-900 border border-slate-700' : 'bg-white border'}`, children: [(0, jsx_runtime_1.jsx)("h2", { className: "font-semibold text-lg mb-4", children: "Quick Links" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-3", children: [(0, jsx_runtime_1.jsx)(link_1.default, { href: "/test-env", className: `px-4 py-2 rounded-lg text-sm ${isDarkMode ? 'bg-slate-800 hover:bg-slate-700' : 'bg-gray-100 hover:bg-gray-200'}`, children: "Debug Tools" }), (0, jsx_runtime_1.jsx)(link_1.default, { href: "/test-env/jwt-inspect", className: `px-4 py-2 rounded-lg text-sm ${isDarkMode ? 'bg-slate-800 hover:bg-slate-700' : 'bg-gray-100 hover:bg-gray-200'}`, children: "JWT Inspector" }), (0, jsx_runtime_1.jsx)(link_1.default, { href: "/account-auth/login", className: `px-4 py-2 rounded-lg text-sm ${isDarkMode ? 'bg-slate-800 hover:bg-slate-700' : 'bg-gray-100 hover:bg-gray-200'}`, children: "Login Page" }), (0, jsx_runtime_1.jsx)(link_1.default, { href: "/profile", className: `px-4 py-2 rounded-lg text-sm ${isDarkMode ? 'bg-slate-800 hover:bg-slate-700' : 'bg-gray-100 hover:bg-gray-200'}`, children: "Profile" }), (0, jsx_runtime_1.jsx)(link_1.default, { href: "/security", className: `px-4 py-2 rounded-lg text-sm ${isDarkMode ? 'bg-slate-800 hover:bg-slate-700' : 'bg-gray-100 hover:bg-gray-200'}`, children: "Security Settings" })] })] })] }), toastVisible && ((0, jsx_runtime_1.jsx)("div", { role: "alert", "aria-live": "polite", className: `fixed bottom-4 right-4 px-6 py-3 rounded-lg shadow-lg transition-opacity ${isDarkMode ? 'bg-slate-800 text-white' : 'bg-gray-900 text-white'}`, children: toastMessage })), modalVisible && ((0, jsx_runtime_1.jsx)("div", { className: "fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50", onClick: (e) => {
133
- if (e.target === e.currentTarget)
134
- setModalVisible(false);
135
- }, children: (0, jsx_runtime_1.jsxs)("div", { ref: modalRef, role: "dialog", "aria-modal": "true", "aria-labelledby": "modal-title", tabIndex: -1, className: `max-w-md w-full p-6 rounded-lg ${isDarkMode ? 'bg-slate-900' : 'bg-white'}`, children: [(0, jsx_runtime_1.jsx)("h3", { id: "modal-title", className: "text-xl font-semibold mb-4", children: "Example Modal" }), (0, jsx_runtime_1.jsx)("p", { className: `mb-6 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`, children: "This is a demonstration of an accessible modal dialog. Press Escape to close, or use Tab to navigate between buttons." }), (0, jsx_runtime_1.jsxs)("div", { className: "flex justify-end gap-3", children: [(0, jsx_runtime_1.jsx)(DemoButton, { variant: "secondary", onClick: () => setModalVisible(false), children: "Cancel" }), (0, jsx_runtime_1.jsx)(DemoButton, { variant: "primary", onClick: () => {
136
- setModalVisible(false);
137
- showToast('Action confirmed!');
138
- }, children: "Confirm" })] })] }) }))] }));
139
- }
140
- exports.default = ShowcasePage;
1
+ "use strict";
2
+ 'use client';
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ShowcasePage = ShowcasePage;
8
+ const jsx_runtime_1 = require("react/jsx-runtime");
9
+ const better_auth_client_1 = require("../../client/better-auth-client");
10
+ const react_1 = require("react");
11
+ const link_1 = __importDefault(require("next/link"));
12
+ // Shared dark mode hook to avoid duplication
13
+ function useDarkMode() {
14
+ const [isDarkMode, setIsDarkMode] = (0, react_1.useState)(false);
15
+ (0, react_1.useEffect)(() => {
16
+ const checkDarkMode = () => {
17
+ const isDark = document.documentElement.classList.contains('dark') ||
18
+ window.matchMedia('(prefers-color-scheme: dark)').matches;
19
+ setIsDarkMode(isDark);
20
+ };
21
+ checkDarkMode();
22
+ const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
23
+ mediaQuery.addEventListener('change', checkDarkMode);
24
+ return () => mediaQuery.removeEventListener('change', checkDarkMode);
25
+ }, []);
26
+ return isDarkMode;
27
+ }
28
+ function FeatureCard({ title, description, status, link, children }) {
29
+ const isDarkMode = useDarkMode();
30
+ const content = ((0, jsx_runtime_1.jsxs)("div", { className: `p-6 rounded-lg h-full ${isDarkMode
31
+ ? 'bg-slate-900 border border-slate-700'
32
+ : 'bg-white border border-gray-200'}`, children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-start justify-between mb-3", children: [(0, jsx_runtime_1.jsx)("h3", { className: "font-semibold text-lg", children: title }), status === 'coming-soon' && ((0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded-full ${isDarkMode ? 'bg-amber-900/50 text-amber-400' : 'bg-amber-100 text-amber-700'}`, children: "Coming Soon" }))] }), (0, jsx_runtime_1.jsx)("p", { className: `text-sm mb-4 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`, children: description }), children] }));
33
+ if (link && status === 'available') {
34
+ return ((0, jsx_runtime_1.jsx)(link_1.default, { href: link, className: "block hover:opacity-90 transition-opacity", children: content }));
35
+ }
36
+ return content;
37
+ }
38
+ function DemoButton({ variant, children, onClick }) {
39
+ const variants = {
40
+ primary: 'bg-blue-600 hover:bg-blue-700 text-white',
41
+ secondary: 'bg-gray-200 hover:bg-gray-300 text-gray-800 dark:bg-slate-700 dark:hover:bg-slate-600 dark:text-white',
42
+ danger: 'bg-red-600 hover:bg-red-700 text-white',
43
+ };
44
+ return ((0, jsx_runtime_1.jsx)("button", { onClick: onClick, className: `px-4 py-2 rounded-lg text-sm font-medium transition-colors ${variants[variant]}`, children: children }));
45
+ }
46
+ /**
47
+ * Feature Showcase Page
48
+ *
49
+ * Demonstrates MVP capabilities with interactive examples.
50
+ *
51
+ * Usage in consuming app:
52
+ * ```typescript
53
+ * // app/showcase/page.tsx
54
+ * export { ShowcasePage as default } from '@payez/next-mvp/pages/showcase';
55
+ * ```
56
+ */
57
+ function ShowcasePage() {
58
+ const { data: sessionData, isPending } = better_auth_client_1.authClient.useSession();
59
+ const session = sessionData;
60
+ const status = isPending ? 'loading' : session ? 'authenticated' : 'unauthenticated';
61
+ const isDarkMode = useDarkMode();
62
+ const [toastVisible, setToastVisible] = (0, react_1.useState)(false);
63
+ const [toastMessage, setToastMessage] = (0, react_1.useState)('');
64
+ const [modalVisible, setModalVisible] = (0, react_1.useState)(false);
65
+ const toastTimeoutRef = (0, react_1.useRef)(null);
66
+ const modalRef = (0, react_1.useRef)(null);
67
+ const previousFocusRef = (0, react_1.useRef)(null);
68
+ // Type the extended session properly
69
+ const extSession = session;
70
+ // Toast with proper cleanup to prevent race conditions
71
+ const showToast = (0, react_1.useCallback)((message) => {
72
+ if (toastTimeoutRef.current) {
73
+ clearTimeout(toastTimeoutRef.current);
74
+ }
75
+ setToastMessage(message);
76
+ setToastVisible(true);
77
+ toastTimeoutRef.current = setTimeout(() => setToastVisible(false), 3000);
78
+ }, []);
79
+ // Cleanup toast timeout on unmount
80
+ (0, react_1.useEffect)(() => {
81
+ return () => {
82
+ if (toastTimeoutRef.current) {
83
+ clearTimeout(toastTimeoutRef.current);
84
+ }
85
+ };
86
+ }, []);
87
+ // Modal focus trap and keyboard handling
88
+ (0, react_1.useEffect)(() => {
89
+ if (!modalVisible)
90
+ return;
91
+ // Store previous focus
92
+ previousFocusRef.current = document.activeElement;
93
+ // Focus the modal
94
+ modalRef.current?.focus();
95
+ // Handle Escape key
96
+ const handleKeyDown = (e) => {
97
+ if (e.key === 'Escape') {
98
+ setModalVisible(false);
99
+ }
100
+ // Focus trap
101
+ if (e.key === 'Tab' && modalRef.current) {
102
+ const focusableElements = modalRef.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
103
+ const firstElement = focusableElements[0];
104
+ const lastElement = focusableElements[focusableElements.length - 1];
105
+ if (e.shiftKey && document.activeElement === firstElement) {
106
+ e.preventDefault();
107
+ lastElement?.focus();
108
+ }
109
+ else if (!e.shiftKey && document.activeElement === lastElement) {
110
+ e.preventDefault();
111
+ firstElement?.focus();
112
+ }
113
+ }
114
+ };
115
+ document.addEventListener('keydown', handleKeyDown);
116
+ return () => {
117
+ document.removeEventListener('keydown', handleKeyDown);
118
+ // Restore focus when modal closes
119
+ previousFocusRef.current?.focus();
120
+ };
121
+ }, [modalVisible]);
122
+ // Get status text for screen readers
123
+ const getStatusText = () => {
124
+ if (status === 'authenticated')
125
+ return 'Authenticated';
126
+ if (status === 'loading')
127
+ return 'Loading';
128
+ return 'Not authenticated';
129
+ };
130
+ return ((0, jsx_runtime_1.jsxs)("div", { className: `min-h-screen p-8 ${isDarkMode ? 'bg-slate-950 text-white' : 'bg-gray-50 text-gray-900'}`, children: [(0, jsx_runtime_1.jsxs)("div", { className: "max-w-6xl mx-auto", children: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-8", children: [(0, jsx_runtime_1.jsx)("h1", { className: "text-3xl font-bold mb-2", children: "MVP Feature Showcase" }), (0, jsx_runtime_1.jsx)("p", { className: `${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`, children: "Interactive demonstrations of @payez/next-mvp capabilities" })] }), (0, jsx_runtime_1.jsxs)("div", { className: `mb-8 p-4 rounded-lg flex items-center justify-between ${isDarkMode ? 'bg-slate-900 border border-slate-700' : 'bg-white border'}`, children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-4", children: [(0, jsx_runtime_1.jsx)("div", { className: `w-3 h-3 rounded-full ${status === 'authenticated' ? 'bg-green-500' :
131
+ status === 'loading' ? 'bg-yellow-500' : 'bg-red-500'}`, "aria-hidden": "true" }), (0, jsx_runtime_1.jsx)("span", { className: "sr-only", children: getStatusText() }), (0, jsx_runtime_1.jsx)("span", { className: "font-medium", children: status === 'authenticated' ? `Logged in as ${session?.user?.email}` :
132
+ status === 'loading' ? 'Loading session...' : 'Not authenticated' })] }), status === 'unauthenticated' && ((0, jsx_runtime_1.jsx)(link_1.default, { href: "/account-auth/login", className: "text-blue-500 hover:text-blue-600 text-sm font-medium", children: "Sign in to test authenticated features" }))] }), (0, jsx_runtime_1.jsxs)("div", { className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8", children: [(0, jsx_runtime_1.jsx)(FeatureCard, { title: "Authentication", description: "Complete auth flow with traditional login, OAuth providers, and password recovery.", status: "available", link: "/account-auth/login", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Email/Password" }), (0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "OAuth" }), (0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "2FA" })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Role-Based Access Control", description: "Fine-grained permissions with roles and access control configuration.", status: "available", children: (0, jsx_runtime_1.jsx)("div", { className: `text-xs p-3 rounded font-mono ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: extSession?.user?.roles ?
133
+ `Roles: ${extSession.user.roles.join(', ')}` :
134
+ 'Sign in to view roles' }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Toast Notifications", description: "Non-blocking notifications for user feedback and status updates.", status: "available", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex gap-2", children: [(0, jsx_runtime_1.jsx)(DemoButton, { variant: "primary", onClick: () => showToast('Success! Action completed.'), children: "Success" }), (0, jsx_runtime_1.jsx)(DemoButton, { variant: "danger", onClick: () => showToast('Error! Something went wrong.'), children: "Error" })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Modal Dialogs", description: "Accessible modal dialogs for confirmations and focused interactions.", status: "available", children: (0, jsx_runtime_1.jsx)(DemoButton, { variant: "secondary", onClick: () => setModalVisible(true), children: "Open Modal" }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Form Validation", description: "Client and server-side validation with real-time feedback and error handling.", status: "available", link: "/account-auth/recovery", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Real-time" }), (0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Password Rules" })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Session Management", description: "JWT-based sessions with automatic refresh and secure token handling.", status: "available", link: "/test-env", children: (0, jsx_runtime_1.jsxs)("div", { className: "space-y-1 text-xs", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex justify-between", children: [(0, jsx_runtime_1.jsx)("span", { children: "Access Token:" }), (0, jsx_runtime_1.jsx)("span", { className: extSession?.accessToken ? 'text-green-500' : 'text-red-500', children: extSession?.accessToken ? 'Valid' : 'None' })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex justify-between", children: [(0, jsx_runtime_1.jsx)("span", { children: "Refresh Token:" }), (0, jsx_runtime_1.jsx)("span", { className: extSession?.refreshToken ? 'text-green-500' : 'text-red-500', children: extSession?.refreshToken ? 'Valid' : 'None' })] })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "User Profile", description: "Profile management with avatar, display name, and account settings.", status: "available", link: "/profile", children: (0, jsx_runtime_1.jsxs)("div", { className: `flex items-center gap-3 p-2 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: [(0, jsx_runtime_1.jsx)("div", { className: "w-10 h-10 rounded-full bg-blue-500 flex items-center justify-center text-white font-medium", children: session?.user?.email?.charAt(0).toUpperCase() || '?' }), (0, jsx_runtime_1.jsx)("div", { className: "text-sm truncate", children: session?.user?.email || 'Not signed in' })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Security Settings", description: "Password management, 2FA configuration, and active session control.", status: "available", link: "/security", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Change Password" }), (0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "2FA Setup" })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Theme Support", description: "Light and dark mode with system preference detection and manual toggle.", status: "available", children: (0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-3", children: (0, jsx_runtime_1.jsxs)("div", { className: `px-3 py-2 rounded text-sm ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: ["Current: ", isDarkMode ? 'Dark' : 'Light'] }) }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Admin Panel", description: "Built-in admin interface for user management, roles, and system configuration.", status: "coming-soon", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "User Management" }), (0, jsx_runtime_1.jsx)("span", { className: `text-xs px-2 py-1 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Schema Browser" })] }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "Data Tables", description: "Sortable, filterable, paginated tables with column customization.", status: "coming-soon", children: (0, jsx_runtime_1.jsx)("div", { className: `text-xs p-3 rounded ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "Sort, filter, paginate, export" }) }), (0, jsx_runtime_1.jsx)(FeatureCard, { title: "API Client", description: "Type-safe API client with automatic auth headers and error handling.", status: "available", children: (0, jsx_runtime_1.jsx)("div", { className: `text-xs p-3 rounded font-mono ${isDarkMode ? 'bg-slate-800' : 'bg-gray-100'}`, children: "fetchWithSession(url, options)" }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: `p-6 rounded-lg ${isDarkMode ? 'bg-slate-900 border border-slate-700' : 'bg-white border'}`, children: [(0, jsx_runtime_1.jsx)("h2", { className: "font-semibold text-lg mb-4", children: "Quick Links" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-3", children: [(0, jsx_runtime_1.jsx)(link_1.default, { href: "/test-env", className: `px-4 py-2 rounded-lg text-sm ${isDarkMode ? 'bg-slate-800 hover:bg-slate-700' : 'bg-gray-100 hover:bg-gray-200'}`, children: "Debug Tools" }), (0, jsx_runtime_1.jsx)(link_1.default, { href: "/test-env/jwt-inspect", className: `px-4 py-2 rounded-lg text-sm ${isDarkMode ? 'bg-slate-800 hover:bg-slate-700' : 'bg-gray-100 hover:bg-gray-200'}`, children: "JWT Inspector" }), (0, jsx_runtime_1.jsx)(link_1.default, { href: "/account-auth/login", className: `px-4 py-2 rounded-lg text-sm ${isDarkMode ? 'bg-slate-800 hover:bg-slate-700' : 'bg-gray-100 hover:bg-gray-200'}`, children: "Login Page" }), (0, jsx_runtime_1.jsx)(link_1.default, { href: "/profile", className: `px-4 py-2 rounded-lg text-sm ${isDarkMode ? 'bg-slate-800 hover:bg-slate-700' : 'bg-gray-100 hover:bg-gray-200'}`, children: "Profile" }), (0, jsx_runtime_1.jsx)(link_1.default, { href: "/security", className: `px-4 py-2 rounded-lg text-sm ${isDarkMode ? 'bg-slate-800 hover:bg-slate-700' : 'bg-gray-100 hover:bg-gray-200'}`, children: "Security Settings" })] })] })] }), toastVisible && ((0, jsx_runtime_1.jsx)("div", { role: "alert", "aria-live": "polite", className: `fixed bottom-4 right-4 px-6 py-3 rounded-lg shadow-lg transition-opacity ${isDarkMode ? 'bg-slate-800 text-white' : 'bg-gray-900 text-white'}`, children: toastMessage })), modalVisible && ((0, jsx_runtime_1.jsx)("div", { className: "fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50", onClick: (e) => {
135
+ if (e.target === e.currentTarget)
136
+ setModalVisible(false);
137
+ }, children: (0, jsx_runtime_1.jsxs)("div", { ref: modalRef, role: "dialog", "aria-modal": "true", "aria-labelledby": "modal-title", tabIndex: -1, className: `max-w-md w-full p-6 rounded-lg ${isDarkMode ? 'bg-slate-900' : 'bg-white'}`, children: [(0, jsx_runtime_1.jsx)("h3", { id: "modal-title", className: "text-xl font-semibold mb-4", children: "Example Modal" }), (0, jsx_runtime_1.jsx)("p", { className: `mb-6 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`, children: "This is a demonstration of an accessible modal dialog. Press Escape to close, or use Tab to navigate between buttons." }), (0, jsx_runtime_1.jsxs)("div", { className: "flex justify-end gap-3", children: [(0, jsx_runtime_1.jsx)(DemoButton, { variant: "secondary", onClick: () => setModalVisible(false), children: "Cancel" }), (0, jsx_runtime_1.jsx)(DemoButton, { variant: "primary", onClick: () => {
138
+ setModalVisible(false);
139
+ showToast('Action confirmed!');
140
+ }, children: "Confirm" })] })] }) }))] }));
141
+ }
142
+ exports.default = ShowcasePage;
@@ -1,98 +1,99 @@
1
- "use strict";
2
- 'use client';
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.EmergencyLogoutPage = EmergencyLogoutPage;
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_1 = require("next-auth/react");
7
- const react_2 = require("react");
8
- /**
9
- * Emergency Logout Page
10
- *
11
- * Nuclear option for clearing auth state when things go wrong.
12
- * Clears cookies, localStorage, and forces NextAuth signout.
13
- *
14
- * Usage in consuming app:
15
- * ```typescript
16
- * // app/test-env/emergency-logout/page.tsx
17
- * export { EmergencyLogoutPage as default } from '@payez/next-mvp/pages/test-env';
18
- * ```
19
- */
20
- function EmergencyLogoutPage() {
21
- const { status } = (0, react_1.useSession)();
22
- const [isDarkMode, setIsDarkMode] = (0, react_2.useState)(false);
23
- const [isLoggingOut, setIsLoggingOut] = (0, react_2.useState)(false);
24
- const [logoutComplete, setLogoutComplete] = (0, react_2.useState)(false);
25
- const [logs, setLogs] = (0, react_2.useState)([]);
26
- (0, react_2.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
- const addLog = (message) => {
38
- setLogs(prev => [...prev, `[${new Date().toISOString().substring(11, 19)}] ${message}`]);
39
- };
40
- const handleEmergencyLogout = async () => {
41
- setIsLoggingOut(true);
42
- setLogs([]);
43
- try {
44
- // Step 1: Clear all cookies
45
- addLog('Clearing cookies...');
46
- document.cookie.split(';').forEach(cookie => {
47
- const name = cookie.split('=')[0].trim();
48
- document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/`;
49
- document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=${window.location.hostname}`;
50
- });
51
- addLog('Cookies cleared');
52
- // Step 2: Clear localStorage
53
- addLog('Clearing localStorage...');
54
- const keysToRemove = [];
55
- for (let i = 0; i < localStorage.length; i++) {
56
- const key = localStorage.key(i);
57
- if (key)
58
- keysToRemove.push(key);
59
- }
60
- keysToRemove.forEach(key => {
61
- localStorage.removeItem(key);
62
- addLog(` Removed: ${key}`);
63
- });
64
- addLog(`localStorage cleared (${keysToRemove.length} items)`);
65
- // Step 3: Clear sessionStorage
66
- addLog('Clearing sessionStorage...');
67
- sessionStorage.clear();
68
- addLog('sessionStorage cleared');
69
- // Step 4: Call NextAuth signOut
70
- addLog('Calling NextAuth signOut...');
71
- await (0, react_1.signOut)({ redirect: false });
72
- addLog('NextAuth signOut complete');
73
- // Step 5: Clear any auth-related fetch cache
74
- addLog('Invalidating caches...');
75
- if ('caches' in window) {
76
- const cacheNames = await caches.keys();
77
- await Promise.all(cacheNames.map(name => caches.delete(name)));
78
- addLog(`Cleared ${cacheNames.length} caches`);
79
- }
80
- addLog('Emergency logout complete!');
81
- setLogoutComplete(true);
82
- }
83
- catch (error) {
84
- addLog(`ERROR: ${error instanceof Error ? error.message : String(error)}`);
85
- }
86
- finally {
87
- setIsLoggingOut(false);
88
- }
89
- };
90
- const handleRedirectHome = () => {
91
- window.location.href = '/';
92
- };
93
- return ((0, jsx_runtime_1.jsx)("div", { className: `min-h-screen p-8 ${isDarkMode ? 'bg-slate-950 text-white' : 'bg-gray-50 text-gray-900'}`, children: (0, jsx_runtime_1.jsxs)("div", { className: "max-w-2xl mx-auto", children: [(0, jsx_runtime_1.jsx)("h1", { className: "text-2xl font-bold mb-2", children: "Emergency Logout" }), (0, jsx_runtime_1.jsx)("p", { className: `mb-6 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`, children: "Nuclear option for when auth gets into a bad state. Clears everything." }), (0, jsx_runtime_1.jsxs)("div", { className: `mb-6 p-4 rounded-lg ${isDarkMode ? 'bg-slate-900' : 'bg-white border'}`, children: [(0, jsx_runtime_1.jsx)("h2", { className: "font-semibold mb-2", children: "Current Status" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: `inline-block w-3 h-3 rounded-full ${status === 'authenticated' ? 'bg-green-500' :
94
- status === 'loading' ? 'bg-yellow-500' : 'bg-red-500'}` }), (0, jsx_runtime_1.jsx)("span", { className: "capitalize", children: status })] })] }), !logoutComplete ? ((0, jsx_runtime_1.jsx)("button", { onClick: handleEmergencyLogout, disabled: isLoggingOut, className: `w-full py-3 px-4 rounded-lg font-semibold transition-colors ${isLoggingOut
95
- ? 'bg-gray-500 cursor-not-allowed'
96
- : 'bg-red-600 hover:bg-red-700 text-white'}`, children: isLoggingOut ? 'Logging out...' : 'Emergency Logout' })) : ((0, jsx_runtime_1.jsxs)("div", { className: "space-y-3", children: [(0, jsx_runtime_1.jsx)("div", { className: `p-4 rounded-lg ${isDarkMode ? 'bg-green-900/30 border border-green-700' : 'bg-green-50 border border-green-200'}`, children: (0, jsx_runtime_1.jsx)("p", { className: `font-semibold ${isDarkMode ? 'text-green-400' : 'text-green-700'}`, children: "Logout complete! All auth state has been cleared." }) }), (0, jsx_runtime_1.jsx)("button", { onClick: handleRedirectHome, className: "w-full py-3 px-4 rounded-lg font-semibold bg-blue-600 hover:bg-blue-700 text-white transition-colors", children: "Go to Home Page" })] })), logs.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: `mt-6 p-4 rounded-lg font-mono text-sm ${isDarkMode ? 'bg-slate-900' : 'bg-gray-100'}`, children: [(0, jsx_runtime_1.jsx)("h3", { className: "font-semibold mb-2", children: "Log" }), (0, jsx_runtime_1.jsx)("div", { className: "space-y-1", children: logs.map((log, i) => ((0, jsx_runtime_1.jsx)("div", { className: log.includes('ERROR') ? 'text-red-500' : isDarkMode ? 'text-gray-300' : 'text-gray-700', children: log }, i))) })] })), (0, jsx_runtime_1.jsxs)("div", { className: `mt-8 p-4 rounded-lg ${isDarkMode ? 'bg-slate-900' : 'bg-white border'}`, children: [(0, jsx_runtime_1.jsx)("h2", { className: "font-semibold mb-2", children: "What this does" }), (0, jsx_runtime_1.jsxs)("ul", { className: `list-disc list-inside space-y-1 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`, children: [(0, jsx_runtime_1.jsx)("li", { children: "Clears all browser cookies" }), (0, jsx_runtime_1.jsx)("li", { children: "Clears localStorage (theme, preferences, etc.)" }), (0, jsx_runtime_1.jsx)("li", { children: "Clears sessionStorage" }), (0, jsx_runtime_1.jsx)("li", { children: "Calls NextAuth signOut" }), (0, jsx_runtime_1.jsx)("li", { children: "Invalidates browser caches" })] })] })] }) }));
97
- }
98
- exports.default = EmergencyLogoutPage;
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.EmergencyLogoutPage = EmergencyLogoutPage;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const better_auth_client_1 = require("../../client/better-auth-client");
7
+ const react_1 = require("react");
8
+ /**
9
+ * Emergency Logout Page
10
+ *
11
+ * Nuclear option for clearing auth state when things go wrong.
12
+ * Clears cookies, localStorage, and forces NextAuth signout.
13
+ *
14
+ * Usage in consuming app:
15
+ * ```typescript
16
+ * // app/test-env/emergency-logout/page.tsx
17
+ * export { EmergencyLogoutPage as default } from '@payez/next-mvp/pages/test-env';
18
+ * ```
19
+ */
20
+ function EmergencyLogoutPage() {
21
+ const { data: sessionData, isPending } = better_auth_client_1.authClient.useSession();
22
+ const status = isPending ? 'loading' : sessionData ? 'authenticated' : 'unauthenticated';
23
+ const [isDarkMode, setIsDarkMode] = (0, react_1.useState)(false);
24
+ const [isLoggingOut, setIsLoggingOut] = (0, react_1.useState)(false);
25
+ const [logoutComplete, setLogoutComplete] = (0, react_1.useState)(false);
26
+ const [logs, setLogs] = (0, react_1.useState)([]);
27
+ (0, react_1.useEffect)(() => {
28
+ const checkDarkMode = () => {
29
+ const isDark = document.documentElement.classList.contains('dark') ||
30
+ window.matchMedia('(prefers-color-scheme: dark)').matches;
31
+ setIsDarkMode(isDark);
32
+ };
33
+ checkDarkMode();
34
+ const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
35
+ mediaQuery.addEventListener('change', checkDarkMode);
36
+ return () => mediaQuery.removeEventListener('change', checkDarkMode);
37
+ }, []);
38
+ const addLog = (message) => {
39
+ setLogs(prev => [...prev, `[${new Date().toISOString().substring(11, 19)}] ${message}`]);
40
+ };
41
+ const handleEmergencyLogout = async () => {
42
+ setIsLoggingOut(true);
43
+ setLogs([]);
44
+ try {
45
+ // Step 1: Clear all cookies
46
+ addLog('Clearing cookies...');
47
+ document.cookie.split(';').forEach(cookie => {
48
+ const name = cookie.split('=')[0].trim();
49
+ document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/`;
50
+ document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=${window.location.hostname}`;
51
+ });
52
+ addLog('Cookies cleared');
53
+ // Step 2: Clear localStorage
54
+ addLog('Clearing localStorage...');
55
+ const keysToRemove = [];
56
+ for (let i = 0; i < localStorage.length; i++) {
57
+ const key = localStorage.key(i);
58
+ if (key)
59
+ keysToRemove.push(key);
60
+ }
61
+ keysToRemove.forEach(key => {
62
+ localStorage.removeItem(key);
63
+ addLog(` Removed: ${key}`);
64
+ });
65
+ addLog(`localStorage cleared (${keysToRemove.length} items)`);
66
+ // Step 3: Clear sessionStorage
67
+ addLog('Clearing sessionStorage...');
68
+ sessionStorage.clear();
69
+ addLog('sessionStorage cleared');
70
+ // Step 4: Call Better Auth signOut
71
+ addLog('Calling Better Auth signOut...');
72
+ await better_auth_client_1.authClient.signOut();
73
+ addLog('Better Auth signOut complete');
74
+ // Step 5: Clear any auth-related fetch cache
75
+ addLog('Invalidating caches...');
76
+ if ('caches' in window) {
77
+ const cacheNames = await caches.keys();
78
+ await Promise.all(cacheNames.map(name => caches.delete(name)));
79
+ addLog(`Cleared ${cacheNames.length} caches`);
80
+ }
81
+ addLog('Emergency logout complete!');
82
+ setLogoutComplete(true);
83
+ }
84
+ catch (error) {
85
+ addLog(`ERROR: ${error instanceof Error ? error.message : String(error)}`);
86
+ }
87
+ finally {
88
+ setIsLoggingOut(false);
89
+ }
90
+ };
91
+ const handleRedirectHome = () => {
92
+ window.location.href = '/';
93
+ };
94
+ return ((0, jsx_runtime_1.jsx)("div", { className: `min-h-screen p-8 ${isDarkMode ? 'bg-slate-950 text-white' : 'bg-gray-50 text-gray-900'}`, children: (0, jsx_runtime_1.jsxs)("div", { className: "max-w-2xl mx-auto", children: [(0, jsx_runtime_1.jsx)("h1", { className: "text-2xl font-bold mb-2", children: "Emergency Logout" }), (0, jsx_runtime_1.jsx)("p", { className: `mb-6 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`, children: "Nuclear option for when auth gets into a bad state. Clears everything." }), (0, jsx_runtime_1.jsxs)("div", { className: `mb-6 p-4 rounded-lg ${isDarkMode ? 'bg-slate-900' : 'bg-white border'}`, children: [(0, jsx_runtime_1.jsx)("h2", { className: "font-semibold mb-2", children: "Current Status" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: `inline-block w-3 h-3 rounded-full ${status === 'authenticated' ? 'bg-green-500' :
95
+ status === 'loading' ? 'bg-yellow-500' : 'bg-red-500'}` }), (0, jsx_runtime_1.jsx)("span", { className: "capitalize", children: status })] })] }), !logoutComplete ? ((0, jsx_runtime_1.jsx)("button", { onClick: handleEmergencyLogout, disabled: isLoggingOut, className: `w-full py-3 px-4 rounded-lg font-semibold transition-colors ${isLoggingOut
96
+ ? 'bg-gray-500 cursor-not-allowed'
97
+ : 'bg-red-600 hover:bg-red-700 text-white'}`, children: isLoggingOut ? 'Logging out...' : 'Emergency Logout' })) : ((0, jsx_runtime_1.jsxs)("div", { className: "space-y-3", children: [(0, jsx_runtime_1.jsx)("div", { className: `p-4 rounded-lg ${isDarkMode ? 'bg-green-900/30 border border-green-700' : 'bg-green-50 border border-green-200'}`, children: (0, jsx_runtime_1.jsx)("p", { className: `font-semibold ${isDarkMode ? 'text-green-400' : 'text-green-700'}`, children: "Logout complete! All auth state has been cleared." }) }), (0, jsx_runtime_1.jsx)("button", { onClick: handleRedirectHome, className: "w-full py-3 px-4 rounded-lg font-semibold bg-blue-600 hover:bg-blue-700 text-white transition-colors", children: "Go to Home Page" })] })), logs.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: `mt-6 p-4 rounded-lg font-mono text-sm ${isDarkMode ? 'bg-slate-900' : 'bg-gray-100'}`, children: [(0, jsx_runtime_1.jsx)("h3", { className: "font-semibold mb-2", children: "Log" }), (0, jsx_runtime_1.jsx)("div", { className: "space-y-1", children: logs.map((log, i) => ((0, jsx_runtime_1.jsx)("div", { className: log.includes('ERROR') ? 'text-red-500' : isDarkMode ? 'text-gray-300' : 'text-gray-700', children: log }, i))) })] })), (0, jsx_runtime_1.jsxs)("div", { className: `mt-8 p-4 rounded-lg ${isDarkMode ? 'bg-slate-900' : 'bg-white border'}`, children: [(0, jsx_runtime_1.jsx)("h2", { className: "font-semibold mb-2", children: "What this does" }), (0, jsx_runtime_1.jsxs)("ul", { className: `list-disc list-inside space-y-1 ${isDarkMode ? 'text-gray-400' : 'text-gray-600'}`, children: [(0, jsx_runtime_1.jsx)("li", { children: "Clears all browser cookies" }), (0, jsx_runtime_1.jsx)("li", { children: "Clears localStorage (theme, preferences, etc.)" }), (0, jsx_runtime_1.jsx)("li", { children: "Clears sessionStorage" }), (0, jsx_runtime_1.jsx)("li", { children: "Calls NextAuth signOut" }), (0, jsx_runtime_1.jsx)("li", { children: "Invalidates browser caches" })] })] })] }) }));
98
+ }
99
+ exports.default = EmergencyLogoutPage;