@xk2800/nextjs-template 0.7.1-beta.8 → 0.7.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/auth/oneTap.tsx +15 -5
- package/components/dashboard/admin/adminActivityLogsTable.tsx +4 -0
- package/components/dashboard/admin/adminUsersTable.tsx +154 -34
- package/components/dashboard/admin/impersonationLogCard.tsx +2 -2
- package/components/dashboard/appSidebar.tsx +2 -2
- package/components/dashboard/deleteAccountCard.tsx +31 -4
- package/components/dashboard/navStyleToggle.tsx +29 -0
- package/components/dashboard/topNav.tsx +95 -0
- package/components/email/email-template-banned.tsx +53 -0
- package/components/ui/alert-dialog.tsx +2 -2
- package/components/ui/avatar.tsx +1 -1
- package/components/ui/badge.tsx +5 -3
- package/components/ui/calendar.tsx +220 -0
- package/components/ui/card.tsx +1 -1
- package/components/ui/category-selector.tsx +215 -0
- package/components/ui/chart.tsx +374 -0
- package/components/ui/column-picker.tsx +140 -0
- package/components/ui/command.tsx +184 -0
- package/components/ui/data-table.tsx +44 -6
- package/components/ui/date-picker-with-presets.tsx +122 -0
- package/components/ui/dialog.tsx +2 -2
- package/components/ui/disclaimer.tsx +4 -0
- package/components/ui/dropdown-menu.tsx +3 -3
- package/components/ui/field.tsx +248 -0
- package/components/ui/info-tooltip.tsx +53 -0
- package/components/ui/input.tsx +10 -1
- package/components/ui/label.tsx +1 -1
- package/components/ui/month-selector.tsx +194 -0
- package/components/ui/navigation-menu.tsx +168 -0
- package/components/ui/pagination.tsx +127 -0
- package/components/ui/popover.tsx +89 -0
- package/components/ui/select.tsx +1 -1
- package/components/ui/source-selector.tsx +164 -0
- package/components/ui/switch.tsx +3 -3
- package/dist/activity/logger.d.mts +3 -1
- package/dist/activity/logger.d.ts +3 -1
- package/dist/activity/logger.js +20 -0
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +1 -1
- package/dist/activity/queries.d.ts +1 -1
- package/dist/activity/queries.js +20 -0
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +3 -3
- package/dist/admin/queries.js +20 -0
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +3 -3
- package/dist/api/feedback.js +527 -70
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +8 -8
- package/dist/api/marketing.js +527 -70
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +10 -10
- package/dist/auth/helpers.js +525 -68
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +8 -8
- package/dist/auth/index.d.mts +149 -10
- package/dist/auth/index.d.ts +149 -10
- package/dist/auth/index.js +525 -68
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +7 -7
- package/dist/{chunk-ZJMFE5B2.mjs → chunk-4C7JHGT5.mjs} +4 -4
- package/dist/{chunk-ZJMFE5B2.mjs.map → chunk-4C7JHGT5.mjs.map} +1 -1
- package/dist/{chunk-7F2POZM6.mjs → chunk-4F6KE47S.mjs} +4 -4
- package/dist/chunk-4F6KE47S.mjs.map +1 -0
- package/dist/{chunk-P2G23JMY.mjs → chunk-A6JXMHOQ.mjs} +5 -5
- package/dist/{chunk-P2G23JMY.mjs.map → chunk-A6JXMHOQ.mjs.map} +1 -1
- package/dist/{chunk-TKWNEKK6.mjs → chunk-HUEDEAY3.mjs} +8 -2
- package/dist/chunk-HUEDEAY3.mjs.map +1 -0
- package/dist/{chunk-6Z3WUSDJ.mjs → chunk-JUSU6UZA.mjs} +5 -5
- package/dist/{chunk-6Z3WUSDJ.mjs.map → chunk-JUSU6UZA.mjs.map} +1 -1
- package/dist/{chunk-TR5XFBTD.mjs → chunk-KA2KMGPY.mjs} +17 -3
- package/dist/chunk-KA2KMGPY.mjs.map +1 -0
- package/dist/{chunk-OVKVD2HH.mjs → chunk-L242CZ64.mjs} +3 -3
- package/dist/{chunk-OVKVD2HH.mjs.map → chunk-L242CZ64.mjs.map} +1 -1
- package/dist/{chunk-C6RGN6QA.mjs → chunk-NQELV53D.mjs} +4 -4
- package/dist/{chunk-C6RGN6QA.mjs.map → chunk-NQELV53D.mjs.map} +1 -1
- package/dist/chunk-VHNGYAIG.mjs +899 -0
- package/dist/chunk-VHNGYAIG.mjs.map +1 -0
- package/dist/{chunk-6MDQRT6U.mjs → chunk-YH53UPUW.mjs} +4 -4
- package/dist/{chunk-6MDQRT6U.mjs.map → chunk-YH53UPUW.mjs.map} +1 -1
- package/dist/config/env.d.mts +2 -0
- package/dist/config/env.d.ts +2 -0
- package/dist/config/env.js +6 -0
- package/dist/config/env.js.map +1 -1
- package/dist/config/env.mjs +1 -1
- package/dist/db/index.d.mts +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +20 -0
- package/dist/db/index.js.map +1 -1
- package/dist/db/index.mjs +3 -3
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +14 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.js +6 -0
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{schema-CN_Y6EXv.d.mts → schema-DzC5zdOq.d.mts} +146 -2
- package/dist/{schema-CN_Y6EXv.d.ts → schema-DzC5zdOq.d.ts} +146 -2
- package/dist/sessions/queries.js +20 -0
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/settings/queries.d.mts +1 -1
- package/dist/settings/queries.d.ts +1 -1
- package/dist/settings/queries.js +20 -0
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +3 -0
- package/dist/users/queries.d.ts +3 -0
- package/dist/users/queries.js +20 -0
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +3 -3
- package/lib/recalculate-columns.ts +8 -2
- package/package.json +28 -18
- package/styles/theme.css +23 -3
- package/dist/chunk-7F2POZM6.mjs.map +0 -1
- package/dist/chunk-7QVIOQ47.mjs +0 -462
- package/dist/chunk-7QVIOQ47.mjs.map +0 -1
- package/dist/chunk-TKWNEKK6.mjs.map +0 -1
- package/dist/chunk-TR5XFBTD.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xk2800/nextjs-template",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2-beta.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -224,11 +224,11 @@
|
|
|
224
224
|
}
|
|
225
225
|
},
|
|
226
226
|
"scripts": {
|
|
227
|
-
"dev": "next dev --turbopack",
|
|
227
|
+
"dev": "bun --env-file=.env.development next dev --turbopack",
|
|
228
228
|
"build": "npm run build:lib && next build",
|
|
229
229
|
"start": "next start",
|
|
230
230
|
"lint": "next lint",
|
|
231
|
-
"test": "bun lib/recalculate-columns.test.ts && bun lib/auth-throttle-limits.test.ts && bun lib/shared-devices.test.ts && bun lib/maintenance.test.ts && bun lib/install-target.test.ts && bun lib/file-upload-accept.test.ts && bun lib/cookie-names.test.ts && bun lib/marketing-email.test.ts && bun scripts/bump-version.test.ts",
|
|
231
|
+
"test": "bun lib/recalculate-columns.test.ts && bun lib/two-factor.test.ts && bun lib/auth-throttle-limits.test.ts && bun lib/shared-devices.test.ts && bun lib/maintenance.test.ts && bun lib/install-target.test.ts && bun lib/file-upload-accept.test.ts && bun lib/cookie-names.test.ts && bun lib/marketing-email.test.ts && bun scripts/bump-version.test.ts",
|
|
232
232
|
"build:lib": "tsup",
|
|
233
233
|
"storybook": "storybook dev -p 6006",
|
|
234
234
|
"build-storybook": "storybook build",
|
|
@@ -266,37 +266,28 @@
|
|
|
266
266
|
"resend": "^6.4.2",
|
|
267
267
|
"server-only": "^0.0.1",
|
|
268
268
|
"ua-parser-js": "2.0.10",
|
|
269
|
+
"web-push": "^3.6.7",
|
|
269
270
|
"zod": "^4.6.5"
|
|
270
271
|
},
|
|
271
272
|
"peerDependencies": {
|
|
272
273
|
"next": "^15.0.0 || ^16.0.0",
|
|
273
274
|
"react": "^19.0.0",
|
|
274
275
|
"react-dom": "^19.0.0",
|
|
275
|
-
"@radix-ui/react-alert-dialog": "^1.1.0",
|
|
276
|
-
"@radix-ui/react-avatar": "^1.1.0",
|
|
277
|
-
"@radix-ui/react-dialog": "^1.1.0",
|
|
278
|
-
"@radix-ui/react-dropdown-menu": "^2.1.0",
|
|
279
|
-
"@radix-ui/react-label": "^2.1.0",
|
|
280
|
-
"@radix-ui/react-separator": "^1.1.0",
|
|
281
|
-
"@radix-ui/react-slot": "^1.2.0",
|
|
282
276
|
"class-variance-authority": "^0.7.0",
|
|
283
277
|
"clsx": "^2.1.0",
|
|
284
278
|
"tailwind-merge": "^3.3.0",
|
|
285
279
|
"lucide-react": "^1.16.0",
|
|
286
280
|
"react-icons": "^5.5.0",
|
|
287
281
|
"next-themes": "^0.4.0",
|
|
288
|
-
"sonner": "^2.0.0"
|
|
282
|
+
"sonner": "^2.0.0",
|
|
283
|
+
"cmdk": "^1.1.1",
|
|
284
|
+
"date-fns": "^4.1.0",
|
|
285
|
+
"react-day-picker": "^10.0.0",
|
|
286
|
+
"recharts": "^3.8.1"
|
|
289
287
|
},
|
|
290
288
|
"devDependencies": {
|
|
291
289
|
"@eslint/eslintrc": "^3",
|
|
292
290
|
"@inquirer/prompts": "^8.5.2",
|
|
293
|
-
"@radix-ui/react-alert-dialog": "^1.1.15",
|
|
294
|
-
"@radix-ui/react-avatar": "^1.1.11",
|
|
295
|
-
"@radix-ui/react-dialog": "^1.1.15",
|
|
296
|
-
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
|
297
|
-
"@radix-ui/react-label": "^2.1.8",
|
|
298
|
-
"@radix-ui/react-separator": "^1.1.8",
|
|
299
|
-
"@radix-ui/react-slot": "^1.2.4",
|
|
300
291
|
"@storybook/addon-docs": "10.6.2",
|
|
301
292
|
"@storybook/nextjs-vite": "10.6.2",
|
|
302
293
|
"@tailwindcss/postcss": "^4",
|
|
@@ -307,9 +298,12 @@
|
|
|
307
298
|
"@types/react": "^19.2.17",
|
|
308
299
|
"@types/react-dom": "^19",
|
|
309
300
|
"@types/ua-parser-js": "^0.7.39",
|
|
301
|
+
"@types/web-push": "^3.6.4",
|
|
310
302
|
"bun-types": "^1.4.2",
|
|
311
303
|
"class-variance-authority": "^0.7.1",
|
|
312
304
|
"clsx": "^2.1.1",
|
|
305
|
+
"cmdk": "^1.1.1",
|
|
306
|
+
"date-fns": "^4.1.0",
|
|
313
307
|
"dotenv": "^17.2.3",
|
|
314
308
|
"drizzle-kit": "^0.31.1",
|
|
315
309
|
"eslint": "^10",
|
|
@@ -319,8 +313,10 @@
|
|
|
319
313
|
"next-themes": "^0.4.6",
|
|
320
314
|
"playwright": "^1.62.0",
|
|
321
315
|
"react": "^19.0.0",
|
|
316
|
+
"react-day-picker": "^10.0.0",
|
|
322
317
|
"react-dom": "^19.0.0",
|
|
323
318
|
"react-icons": "^5.5.0",
|
|
319
|
+
"recharts": "^3.8.1",
|
|
324
320
|
"sonner": "^2.0.7",
|
|
325
321
|
"storybook": "10.6.2",
|
|
326
322
|
"tailwind-merge": "^3.3.1",
|
|
@@ -330,5 +326,19 @@
|
|
|
330
326
|
"tw-animate-css": "^1.3.6",
|
|
331
327
|
"typescript": "^6.0.3",
|
|
332
328
|
"vite": "^8.3.4"
|
|
329
|
+
},
|
|
330
|
+
"peerDependenciesMeta": {
|
|
331
|
+
"cmdk": {
|
|
332
|
+
"optional": true
|
|
333
|
+
},
|
|
334
|
+
"date-fns": {
|
|
335
|
+
"optional": true
|
|
336
|
+
},
|
|
337
|
+
"react-day-picker": {
|
|
338
|
+
"optional": true
|
|
339
|
+
},
|
|
340
|
+
"recharts": {
|
|
341
|
+
"optional": true
|
|
342
|
+
}
|
|
333
343
|
}
|
|
334
344
|
}
|
package/styles/theme.css
CHANGED
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
--color-input: var(--input);
|
|
28
28
|
--color-border: var(--border);
|
|
29
29
|
--color-destructive: var(--destructive);
|
|
30
|
+
--color-success: var(--success);
|
|
31
|
+
--color-success-foreground: var(--success-foreground);
|
|
30
32
|
--color-accent-foreground: var(--accent-foreground);
|
|
31
33
|
--color-accent: var(--accent);
|
|
32
34
|
--color-muted-foreground: var(--muted-foreground);
|
|
@@ -39,14 +41,28 @@
|
|
|
39
41
|
--color-popover: var(--popover);
|
|
40
42
|
--color-card-foreground: var(--card-foreground);
|
|
41
43
|
--color-card: var(--card);
|
|
42
|
-
--radius
|
|
43
|
-
--radius-
|
|
44
|
+
/* Scaled, not offset, so --radius: 0 squares every corner. */
|
|
45
|
+
--radius-sm: calc(var(--radius) * 0.6);
|
|
46
|
+
--radius-md: calc(var(--radius) * 0.8);
|
|
44
47
|
--radius-lg: var(--radius);
|
|
45
|
-
--radius-xl: calc(var(--radius)
|
|
48
|
+
--radius-xl: calc(var(--radius) * 1.4);
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
/* Shape tokens: override in your globals.css to restyle every template
|
|
52
|
+
* component at once (they work per scope too, e.g. [data-ui="soft"]).
|
|
53
|
+
* Components use them as border-(length:--x) / shadow-(--x) so a className
|
|
54
|
+
* passed to a component still overrides them through tailwind-merge. */
|
|
48
55
|
:root {
|
|
49
56
|
--radius: 0.625rem;
|
|
57
|
+
--pill-radius: 9999px; /* switch and badge */
|
|
58
|
+
--surface-border-width: 1px; /* cards, dialogs, menus, select lists */
|
|
59
|
+
--surface-border-color: var(--border);
|
|
60
|
+
--card-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
|
|
61
|
+
--popover-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
|
|
62
|
+
--dialog-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
:root {
|
|
50
66
|
--background: oklch(1 0 0);
|
|
51
67
|
--foreground: oklch(0.145 0 0);
|
|
52
68
|
--card: oklch(1 0 0);
|
|
@@ -62,6 +78,8 @@
|
|
|
62
78
|
--accent: oklch(0.97 0 0);
|
|
63
79
|
--accent-foreground: oklch(0.205 0 0);
|
|
64
80
|
--destructive: oklch(0.577 0.245 27.325);
|
|
81
|
+
--success: oklch(0.55 0.15 145);
|
|
82
|
+
--success-foreground: oklch(0.984 0.003 247.858);
|
|
65
83
|
--border: oklch(0.922 0 0);
|
|
66
84
|
--input: oklch(0.922 0 0);
|
|
67
85
|
--ring: oklch(0.708 0 0);
|
|
@@ -96,6 +114,8 @@
|
|
|
96
114
|
--accent: oklch(0.269 0 0);
|
|
97
115
|
--accent-foreground: oklch(0.985 0 0);
|
|
98
116
|
--destructive: oklch(0.704 0.191 22.216);
|
|
117
|
+
--success: oklch(0.7 0.16 145);
|
|
118
|
+
--success-foreground: oklch(0.15 0.05 145);
|
|
99
119
|
--border: oklch(1 0 0 / 10%);
|
|
100
120
|
--input: oklch(1 0 0 / 15%);
|
|
101
121
|
--ring: oklch(0.556 0 0);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/activity-logger.ts"],"names":[],"mappings":";;;;AAsCA,eAAsB,WAAA,CAAY;AAAA,EAChC,MAAA;AAAA,EACA,MAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,WAAA;AAAA,EACA,EAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAAA,EAAsB;AACpB,EAAA,IAAI;AACF,IAAA,MAAM,EAAA,CAAG,MAAA,CAAO,YAAY,CAAA,CAAE,MAAA,CAAO;AAAA,MACnC,MAAA;AAAA,MACA,MAAA;AAAA,MACA,WAAA;AAAA,MACA,WAAW,SAAA,IAAa,IAAA;AAAA,MACxB,WAAW,SAAA,IAAa,IAAA;AAAA,MACxB,QAAA,EAAU,QAAA,GAAW,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAA,GAAI,IAAA;AAAA,MAChD,aAAa,WAAA,IAAe,IAAA;AAAA,MAC5B,IAAI,EAAA,IAAM,IAAA;AAAA,MACV,SAAS,OAAA,IAAW,IAAA;AAAA,MACpB,YAAY,UAAA,IAAc,IAAA;AAAA,MAC1B,SAAS,OAAA,IAAW,IAAA;AAAA,MACpB,MAAM,IAAA,IAAQ;AAAA,KACf,CAAA;AAAA,EACH,SAAS,KAAA,EAAO;AACd,IAAA,OAAA,CAAQ,KAAA,CAAM,2BAA2B,KAAK,CAAA;AAAA,EAEhD;AACF","file":"chunk-7F2POZM6.mjs","sourcesContent":["import \"server-only\"\nimport { db } from \"../server/db\"\nimport { activityLogs } from \"../server/db/schema\"\n\nexport type ActivityAction =\n | 'login'\n | 'logout'\n | 'login_failed'\n | 'password_changed'\n | 'email_changed'\n | 'profile_updated'\n | 'session_revoked'\n | 'user_deleted'\n | 'user_banned'\n | 'user_unbanned'\n | 'role_changed'\n | 'impersonation_started'\n | 'impersonation_stopped'\n | 'settings_changed'\n | 'passkey_added'\n | 'passkey_removed'\n\ninterface LogActivityParams {\n userId: string\n action: ActivityAction\n description: string\n ipAddress?: string | null\n userAgent?: string | null\n metadata?: Record<string, any>\n // Populated on 'login' events only — see server/auth.ts's session.create hook.\n referrerUrl?: string | null\n os?: string | null\n browser?: string | null\n deviceType?: string | null\n country?: string | null\n city?: string | null\n}\n\nexport async function logActivity({\n userId,\n action,\n description,\n ipAddress,\n userAgent,\n metadata,\n referrerUrl,\n os,\n browser,\n deviceType,\n country,\n city,\n}: LogActivityParams) {\n try {\n await db.insert(activityLogs).values({\n userId,\n action,\n description,\n ipAddress: ipAddress || null,\n userAgent: userAgent || null,\n metadata: metadata ? JSON.stringify(metadata) : null,\n referrerUrl: referrerUrl || null,\n os: os || null,\n browser: browser || null,\n deviceType: deviceType || null,\n country: country || null,\n city: city || null,\n })\n } catch (error) {\n console.error('Failed to log activity:', error)\n // Don't throw - activity logging should not break the app\n }\n}\n"]}
|
package/dist/chunk-7QVIOQ47.mjs
DELETED
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
import { logActivity } from './chunk-7F2POZM6.mjs';
|
|
2
|
-
import { getClientIp, parseUserAgent, lookupGeoLocation, formatLocation, formatDeviceInfo, WINDOW_MS, isOverLimit, MAX_IP, RETENTION_MS } from './chunk-6OAHCEDJ.mjs';
|
|
3
|
-
import { getEffectiveAuthFlags } from './chunk-P2G23JMY.mjs';
|
|
4
|
-
import { getResend, EMAIL_FROM } from './chunk-OVKVD2HH.mjs';
|
|
5
|
-
import { db } from './chunk-ZJMFE5B2.mjs';
|
|
6
|
-
import { users, sessions, passkeys, twoFactors, verifications, accounts, authThrottle } from './chunk-TR5XFBTD.mjs';
|
|
7
|
-
import { config } from './chunk-TKWNEKK6.mjs';
|
|
8
|
-
import { __spreadValues, __spreadProps } from './chunk-3465SI5N.mjs';
|
|
9
|
-
import 'server-only';
|
|
10
|
-
import { betterAuth } from 'better-auth';
|
|
11
|
-
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
|
|
12
|
-
import { createId } from '@paralleldrive/cuid2';
|
|
13
|
-
import { sql, eq, lt } from 'drizzle-orm';
|
|
14
|
-
import { admin, twoFactor, oneTap } from 'better-auth/plugins';
|
|
15
|
-
import { passkey } from '@better-auth/passkey';
|
|
16
|
-
import { createAuthMiddleware, APIError, getSessionFromCtx } from 'better-auth/api';
|
|
17
|
-
|
|
18
|
-
// lib/cookie-names.ts
|
|
19
|
-
var LOGIN_REFERRER_COOKIE = "login_referrer";
|
|
20
|
-
var DEVICE_FINGERPRINT_HEADER = "x-device-fingerprint";
|
|
21
|
-
async function isDeviceThrottled(fingerprint, max) {
|
|
22
|
-
try {
|
|
23
|
-
const [row] = await db.select({ count: authThrottle.count, windowStart: authThrottle.windowStart }).from(authThrottle).where(eq(authThrottle.fingerprint, fingerprint)).limit(1);
|
|
24
|
-
return isOverLimit(row, Date.now(), max);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error("auth-throttle read failed, allowing request", error);
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function recordDeviceAttempt(fingerprint, meta) {
|
|
31
|
-
const now = /* @__PURE__ */ new Date();
|
|
32
|
-
const cutoff = new Date(now.getTime() - WINDOW_MS);
|
|
33
|
-
const seen = {
|
|
34
|
-
lastAttemptAt: now,
|
|
35
|
-
ipAddress: meta.ipAddress,
|
|
36
|
-
userAgent: meta.userAgent,
|
|
37
|
-
lastEmail: meta.email,
|
|
38
|
-
lastKind: meta.kind
|
|
39
|
-
};
|
|
40
|
-
try {
|
|
41
|
-
await db.insert(authThrottle).values(__spreadValues({ fingerprint, count: 1, windowStart: now }, seen)).onConflictDoUpdate({
|
|
42
|
-
target: authThrottle.fingerprint,
|
|
43
|
-
set: __spreadValues({
|
|
44
|
-
count: sql`case when ${authThrottle.windowStart} < ${cutoff} then 1 else ${authThrottle.count} + 1 end`,
|
|
45
|
-
windowStart: sql`case when ${authThrottle.windowStart} < ${cutoff} then ${now} else ${authThrottle.windowStart} end`
|
|
46
|
-
}, seen)
|
|
47
|
-
});
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error("auth-throttle write failed", error);
|
|
50
|
-
}
|
|
51
|
-
await pruneStaleRows(now);
|
|
52
|
-
}
|
|
53
|
-
var PRUNE_EVERY_MS = 60 * 60 * 1e3;
|
|
54
|
-
var lastPrune = 0;
|
|
55
|
-
async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
56
|
-
if (now.getTime() - lastPrune < PRUNE_EVERY_MS) return;
|
|
57
|
-
lastPrune = now.getTime();
|
|
58
|
-
try {
|
|
59
|
-
await db.delete(authThrottle).where(lt(authThrottle.lastAttemptAt, new Date(now.getTime() - RETENTION_MS)));
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.error("auth-throttle prune failed", error);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
async function clearDeviceThrottle(fingerprint) {
|
|
65
|
-
try {
|
|
66
|
-
await db.delete(authThrottle).where(eq(authThrottle.fingerprint, fingerprint));
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.error("auth-throttle clear failed", error);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// server/auth.ts
|
|
73
|
-
async function logFailedLogin(ctx) {
|
|
74
|
-
var _a, _b, _c;
|
|
75
|
-
try {
|
|
76
|
-
const raw = (_a = ctx.body) == null ? void 0 : _a.email;
|
|
77
|
-
const email = typeof raw === "string" ? raw.toLowerCase() : null;
|
|
78
|
-
if (!email) return;
|
|
79
|
-
const [user] = await db.select({ id: users.id }).from(users).where(eq(users.email, email)).limit(1);
|
|
80
|
-
if (!user) return;
|
|
81
|
-
await logActivity({
|
|
82
|
-
userId: user.id,
|
|
83
|
-
action: "login_failed",
|
|
84
|
-
description: "Failed login attempt",
|
|
85
|
-
ipAddress: getClientIp(ctx.headers),
|
|
86
|
-
userAgent: (_c = (_b = ctx.headers) == null ? void 0 : _b.get("user-agent")) != null ? _c : null
|
|
87
|
-
});
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.error("Failed to log login_failed activity", error);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async function notifyPasskeyChange(ctx, action) {
|
|
93
|
-
var _a, _b, _c, _d;
|
|
94
|
-
try {
|
|
95
|
-
const session = await getSessionFromCtx(ctx);
|
|
96
|
-
const user = session == null ? void 0 : session.user;
|
|
97
|
-
if (!user) return;
|
|
98
|
-
const ip = getClientIp(ctx.headers);
|
|
99
|
-
await logActivity({
|
|
100
|
-
userId: user.id,
|
|
101
|
-
action: action === "added" ? "passkey_added" : "passkey_removed",
|
|
102
|
-
description: `Passkey ${action}`,
|
|
103
|
-
ipAddress: ip,
|
|
104
|
-
userAgent: (_b = (_a = ctx.headers) == null ? void 0 : _a.get("user-agent")) != null ? _b : null
|
|
105
|
-
});
|
|
106
|
-
if (!config.RESEND_API_KEY) return;
|
|
107
|
-
const { EmailTemplatePasskeyChange } = await import('./email-template-passkey-change-F5Q2SXHD.mjs');
|
|
108
|
-
await (await getResend()).emails.send({
|
|
109
|
-
from: EMAIL_FROM,
|
|
110
|
-
to: [user.email],
|
|
111
|
-
subject: action === "added" ? "A passkey was added to your account" : "A passkey was removed from your account",
|
|
112
|
-
react: EmailTemplatePasskeyChange({
|
|
113
|
-
firstName: user.name || "there",
|
|
114
|
-
action,
|
|
115
|
-
device: formatDeviceInfo(parseUserAgent((_d = (_c = ctx.headers) == null ? void 0 : _c.get("user-agent")) != null ? _d : null)),
|
|
116
|
-
location: formatLocation(lookupGeoLocation(ip)),
|
|
117
|
-
ipAddress: ip || "Unknown",
|
|
118
|
-
when: (/* @__PURE__ */ new Date()).toUTCString(),
|
|
119
|
-
manageUrl: `${process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || ""}/dashboard/settings`
|
|
120
|
-
})
|
|
121
|
-
});
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error("Failed to send passkey-change notification", error);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function createAuth(overrides = {}) {
|
|
127
|
-
const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
|
|
128
|
-
google: {
|
|
129
|
-
clientId: process.env.AUTH_GOOGLE_ID || process.env.GOOGLE_CLIENT_ID || "",
|
|
130
|
-
clientSecret: process.env.AUTH_GOOGLE_SECRET || process.env.GOOGLE_CLIENT_SECRET || ""
|
|
131
|
-
}
|
|
132
|
-
} : {}), overrides.socialProviders);
|
|
133
|
-
const emailAndPasswordEnabled = config.AUTH_ENABLE_EMAIL_PASSWORD;
|
|
134
|
-
const hasEnabledSocialProvider = Object.values(socialProviders).some(Boolean);
|
|
135
|
-
if (!hasEnabledSocialProvider && !emailAndPasswordEnabled) {
|
|
136
|
-
throw new Error(
|
|
137
|
-
"No auth provider is enabled \u2014 every social provider is off and emailAndPassword.enabled is false. Enable AUTH_ENABLE_GOOGLE / AUTH_ENABLE_EMAIL_PASSWORD, or pass your own provider via createAuth({ socialProviders: {...} })."
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
const baseURL = process.env.NEXTAUTH_URL || process.env.BETTER_AUTH_URL || "http://localhost:3000";
|
|
141
|
-
return betterAuth({
|
|
142
|
-
database: drizzleAdapter(db, {
|
|
143
|
-
provider: "pg",
|
|
144
|
-
schema: {
|
|
145
|
-
user: users,
|
|
146
|
-
account: accounts,
|
|
147
|
-
session: sessions,
|
|
148
|
-
verification: verifications,
|
|
149
|
-
twoFactor: twoFactors,
|
|
150
|
-
passkey: passkeys
|
|
151
|
-
}
|
|
152
|
-
}),
|
|
153
|
-
// Session configuration (30 days expiration matching previous NextAuth setup)
|
|
154
|
-
session: {
|
|
155
|
-
expiresIn: 60 * 60 * 24 * 30,
|
|
156
|
-
// 30 days
|
|
157
|
-
updateAge: 60 * 60 * 24,
|
|
158
|
-
// Update session every 24 hours
|
|
159
|
-
cookieCache: {
|
|
160
|
-
enabled: true,
|
|
161
|
-
// Enable hybrid session caching for performance
|
|
162
|
-
maxAge: 5 * 60
|
|
163
|
-
// 5 minutes
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
// Email & Password Authentication (replaces Credentials provider)
|
|
167
|
-
// Toggle per-project via AUTH_ENABLE_EMAIL_PASSWORD in that project's own .env.*
|
|
168
|
-
emailAndPassword: {
|
|
169
|
-
enabled: emailAndPasswordEnabled,
|
|
170
|
-
requireEmailVerification: false,
|
|
171
|
-
// `url` is fully composed by better-auth (baseURL + verification token +
|
|
172
|
-
// callbackURL) — see app/(auth)/forgot-password and reset-password for
|
|
173
|
-
// the pages this points at.
|
|
174
|
-
async sendResetPassword({ user, url }) {
|
|
175
|
-
const { EmailTemplateResetPassword } = await import('./email-template-reset-password-QTCQNXOD.mjs');
|
|
176
|
-
await (await getResend()).emails.send({
|
|
177
|
-
from: EMAIL_FROM,
|
|
178
|
-
to: [user.email],
|
|
179
|
-
subject: "Reset your password",
|
|
180
|
-
react: EmailTemplateResetPassword({ firstName: user.name || "there", url })
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
// Email verification. `requireEmailVerification` above stays false, so this
|
|
185
|
-
// is opt-in: users trigger it from the dashboard via
|
|
186
|
-
// authClient.sendVerificationEmail(). better-auth composes `url`
|
|
187
|
-
// (baseURL + token + callbackURL) and serves the /api/auth/verify-email
|
|
188
|
-
// callback that flips users.emailVerified on click.
|
|
189
|
-
emailVerification: {
|
|
190
|
-
autoSignInAfterVerification: true,
|
|
191
|
-
async sendVerificationEmail({ user, url }) {
|
|
192
|
-
const { EmailTemplateVerifyEmail } = await import('./email-template-verify-email-WZDCCAKK.mjs');
|
|
193
|
-
await (await getResend()).emails.send({
|
|
194
|
-
from: EMAIL_FROM,
|
|
195
|
-
to: [user.email],
|
|
196
|
-
subject: "Confirm your email",
|
|
197
|
-
react: EmailTemplateVerifyEmail({ firstName: user.name || "there", url })
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
// Social Providers — google is included by default; toggle per-project via
|
|
202
|
-
// AUTH_ENABLE_GOOGLE. overrides.socialProviders can still add more (or replace it).
|
|
203
|
-
socialProviders,
|
|
204
|
-
// User schema configuration
|
|
205
|
-
user: {
|
|
206
|
-
additionalFields: {
|
|
207
|
-
role: {
|
|
208
|
-
type: "string",
|
|
209
|
-
required: false,
|
|
210
|
-
defaultValue: "user",
|
|
211
|
-
input: false
|
|
212
|
-
// Prevent users from setting their own role
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
// Self-service "Delete account" (dashboard Settings → Danger zone).
|
|
216
|
-
// Credential users confirm with their password; OAuth-only users have
|
|
217
|
-
// no password, so better-auth instead requires a session younger than
|
|
218
|
-
// `freshAge` (default 1 day). Every user-owned table cascades on delete.
|
|
219
|
-
// Impersonation and last-admin guards live in hooks.before below.
|
|
220
|
-
deleteUser: { enabled: true }
|
|
221
|
-
},
|
|
222
|
-
// Advanced options
|
|
223
|
-
advanced: {
|
|
224
|
-
database: {
|
|
225
|
-
generateId: () => createId()
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
// Every new session row corresponds to a sign-in (credential or OAuth) —
|
|
229
|
-
// use that as the "last logged in" signal rather than session updates,
|
|
230
|
-
// which also fire on cookie-cache refresh / expiry extension.
|
|
231
|
-
databaseHooks: {
|
|
232
|
-
session: {
|
|
233
|
-
create: {
|
|
234
|
-
async after(session, context) {
|
|
235
|
-
var _a, _b, _c, _d;
|
|
236
|
-
const impersonatedBy = session.impersonatedBy;
|
|
237
|
-
if (impersonatedBy) {
|
|
238
|
-
const target = await db.select({ email: users.email }).from(users).where(eq(users.id, session.userId)).limit(1);
|
|
239
|
-
await logActivity({
|
|
240
|
-
userId: impersonatedBy,
|
|
241
|
-
action: "impersonation_started",
|
|
242
|
-
description: `Admin started impersonating ${(_b = (_a = target[0]) == null ? void 0 : _a.email) != null ? _b : session.userId}`,
|
|
243
|
-
metadata: { impersonatedUserId: session.userId }
|
|
244
|
-
});
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
try {
|
|
248
|
-
await db.update(users).set({ lastLoginAt: /* @__PURE__ */ new Date() }).where(eq(users.id, session.userId));
|
|
249
|
-
} catch (error) {
|
|
250
|
-
console.error("Failed to update lastLoginAt", error);
|
|
251
|
-
}
|
|
252
|
-
try {
|
|
253
|
-
const headers = context == null ? void 0 : context.headers;
|
|
254
|
-
const ipAddress = getClientIp(headers);
|
|
255
|
-
const userAgent = (_c = headers == null ? void 0 : headers.get("user-agent")) != null ? _c : null;
|
|
256
|
-
const referrerUrl = ((_d = context == null ? void 0 : context.getCookie) == null ? void 0 : _d.call(context, LOGIN_REFERRER_COOKIE)) || (headers == null ? void 0 : headers.get("referer")) || null;
|
|
257
|
-
const device = parseUserAgent(userAgent);
|
|
258
|
-
const geo = lookupGeoLocation(ipAddress);
|
|
259
|
-
const [{ count }] = await db.select({ count: sql`count(*)` }).from(sessions).where(eq(sessions.userId, session.userId));
|
|
260
|
-
const isFirstSession = Number(count) <= 1;
|
|
261
|
-
await logActivity({
|
|
262
|
-
userId: session.userId,
|
|
263
|
-
action: "login",
|
|
264
|
-
description: isFirstSession ? "New account registered and signed in" : "User logged in",
|
|
265
|
-
ipAddress,
|
|
266
|
-
userAgent,
|
|
267
|
-
referrerUrl,
|
|
268
|
-
os: device.os,
|
|
269
|
-
browser: device.browser,
|
|
270
|
-
deviceType: device.deviceType,
|
|
271
|
-
country: geo.country,
|
|
272
|
-
city: geo.city
|
|
273
|
-
});
|
|
274
|
-
} catch (error) {
|
|
275
|
-
console.error("Failed to log login activity", error);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
// better-auth's admin plugin ends impersonation by deleting the
|
|
282
|
-
// impersonation session and restoring the admin's original session
|
|
283
|
-
// straight from a signed cookie — it never runs session.create, so
|
|
284
|
-
// there's no databaseHooks entry point to log the stop event from.
|
|
285
|
-
// Reading the session here (before the endpoint deletes it) is the only
|
|
286
|
-
// point where both the admin id and the impersonated user id are still
|
|
287
|
-
// available together.
|
|
288
|
-
hooks: {
|
|
289
|
-
before: createAuthMiddleware(async (ctx) => {
|
|
290
|
-
var _a, _b, _c, _d;
|
|
291
|
-
if (ctx.path === "/sign-in/email" || ctx.path === "/sign-up/email") {
|
|
292
|
-
const fingerprint = (_a = ctx.headers) == null ? void 0 : _a.get(DEVICE_FINGERPRINT_HEADER);
|
|
293
|
-
const ip = getClientIp(ctx.headers);
|
|
294
|
-
const throttled = fingerprint && await isDeviceThrottled(fingerprint) || ip && await isDeviceThrottled(`ip:${ip}`, MAX_IP);
|
|
295
|
-
if (throttled) {
|
|
296
|
-
throw new APIError("TOO_MANY_REQUESTS", {
|
|
297
|
-
message: "Too many attempts from this device. Try again in a few minutes."
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (ctx.path === "/sign-in/social") {
|
|
302
|
-
if (((_b = ctx.body) == null ? void 0 : _b.provider) === "google") {
|
|
303
|
-
const flags = await getEffectiveAuthFlags();
|
|
304
|
-
if (!flags.google) {
|
|
305
|
-
throw new APIError("FORBIDDEN", { message: "Google sign-in is currently disabled." });
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
if (ctx.path === "/sign-in/email") {
|
|
311
|
-
const flags = await getEffectiveAuthFlags();
|
|
312
|
-
if (!flags.emailPassword) {
|
|
313
|
-
throw new APIError("FORBIDDEN", { message: "Email/password sign-in is currently disabled." });
|
|
314
|
-
}
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
if (ctx.path === "/one-tap/callback") {
|
|
318
|
-
const flags = await getEffectiveAuthFlags();
|
|
319
|
-
if (!flags.google || !flags.oneTap) {
|
|
320
|
-
throw new APIError("FORBIDDEN", { message: "Google One Tap is currently disabled." });
|
|
321
|
-
}
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
if (ctx.path === "/delete-user") {
|
|
325
|
-
const current2 = await getSessionFromCtx(ctx, { disableCookieCache: true });
|
|
326
|
-
if (!current2) return;
|
|
327
|
-
if (current2.session.impersonatedBy) {
|
|
328
|
-
throw new APIError("FORBIDDEN", { message: "Stop impersonating before deleting an account." });
|
|
329
|
-
}
|
|
330
|
-
if (current2.user.role === "admin") {
|
|
331
|
-
const [{ count }] = await db.select({ count: sql`count(*)` }).from(users).where(eq(users.role, "admin"));
|
|
332
|
-
if (Number(count) <= 1) {
|
|
333
|
-
throw new APIError("FORBIDDEN", { message: "You're the only admin. Promote another user to admin first." });
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
if (ctx.path !== "/admin/stop-impersonating") return;
|
|
339
|
-
const current = await getSessionFromCtx(ctx, { disableCookieCache: true });
|
|
340
|
-
if (current == null ? void 0 : current.session.impersonatedBy) {
|
|
341
|
-
const target = await db.select({ email: users.email }).from(users).where(eq(users.id, current.session.userId)).limit(1);
|
|
342
|
-
await logActivity({
|
|
343
|
-
userId: current.session.impersonatedBy,
|
|
344
|
-
action: "impersonation_stopped",
|
|
345
|
-
description: `Admin stopped impersonating ${(_d = (_c = target[0]) == null ? void 0 : _c.email) != null ? _d : current.session.userId}`,
|
|
346
|
-
metadata: { impersonatedUserId: current.session.userId }
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
}),
|
|
350
|
-
after: createAuthMiddleware(async (ctx) => {
|
|
351
|
-
var _a, _b, _c, _d;
|
|
352
|
-
if (ctx.path === "/passkey/verify-registration" || ctx.path === "/passkey/delete-passkey") {
|
|
353
|
-
if (ctx.context.returned instanceof APIError) return;
|
|
354
|
-
await notifyPasskeyChange(
|
|
355
|
-
ctx,
|
|
356
|
-
ctx.path === "/passkey/verify-registration" ? "added" : "removed"
|
|
357
|
-
);
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
if (ctx.path !== "/sign-in/email" && ctx.path !== "/sign-up/email") return;
|
|
361
|
-
const fingerprint = (_a = ctx.headers) == null ? void 0 : _a.get(DEVICE_FINGERPRINT_HEADER);
|
|
362
|
-
const ip = getClientIp(ctx.headers);
|
|
363
|
-
const ipKey = ip ? `ip:${ip}` : null;
|
|
364
|
-
if (!fingerprint && !ipKey) return;
|
|
365
|
-
const failed = ctx.context.returned instanceof APIError;
|
|
366
|
-
const rawEmail = (_b = ctx.body) == null ? void 0 : _b.email;
|
|
367
|
-
const meta = {
|
|
368
|
-
ipAddress: ip,
|
|
369
|
-
userAgent: (_d = (_c = ctx.headers) == null ? void 0 : _c.get("user-agent")) != null ? _d : null,
|
|
370
|
-
email: typeof rawEmail === "string" ? rawEmail.toLowerCase() : null
|
|
371
|
-
};
|
|
372
|
-
const keys = [fingerprint, ipKey].filter((k) => !!k);
|
|
373
|
-
if (ctx.path === "/sign-up/email") {
|
|
374
|
-
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signup" }))));
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
if (failed) {
|
|
378
|
-
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
379
|
-
await logFailedLogin(ctx);
|
|
380
|
-
} else {
|
|
381
|
-
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
382
|
-
}
|
|
383
|
-
})
|
|
384
|
-
},
|
|
385
|
-
// Base URL for callbacks
|
|
386
|
-
baseURL,
|
|
387
|
-
// Secret for signing cookies and tokens
|
|
388
|
-
secret: process.env.AUTH_SECRET,
|
|
389
|
-
// The OAuth `state` is a one-time verification row: the callback consumes
|
|
390
|
-
// and deletes it. When the same callback URL gets hit twice (browser
|
|
391
|
-
// prefetch / bfcache / double nav — common on a repeat Google sign-in
|
|
392
|
-
// where Google auto-redirects with no consent screen), the first hit
|
|
393
|
-
// logs the user in and the second finds no `state` row and throws
|
|
394
|
-
// `please_restart_the_process`. Default sends that to better-auth's bare
|
|
395
|
-
// error page; point it at /login instead, which already bounces an
|
|
396
|
-
// authenticated user straight to their callbackUrl — so the losing race
|
|
397
|
-
// just lands them logged in. See better-auth#5658 / #6544.
|
|
398
|
-
onAPIError: {
|
|
399
|
-
errorURL: "/login"
|
|
400
|
-
},
|
|
401
|
-
plugins: [
|
|
402
|
-
// Registered for impersonation (auth.api.impersonateUser / stopImpersonating)
|
|
403
|
-
// only — role/ban/delete stay on our own custom routes above. adminRoles
|
|
404
|
-
// matches our existing role column so the plugin's own permission checks
|
|
405
|
-
// line up with hasRole(role, 'admin'). banReason is remapped onto our
|
|
406
|
-
// existing bannedReason column instead of adding a duplicate field.
|
|
407
|
-
admin({
|
|
408
|
-
adminRoles: ["admin"],
|
|
409
|
-
schema: {
|
|
410
|
-
user: {
|
|
411
|
-
fields: {
|
|
412
|
-
banReason: "bannedReason"
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}),
|
|
417
|
-
// TOTP second factor + encrypted backup codes. `issuer` is the label
|
|
418
|
-
// shown in the user's authenticator app.
|
|
419
|
-
twoFactor({ issuer: config.APP_NAME }),
|
|
420
|
-
// WebAuthn passkeys (Touch ID / Windows Hello / security keys) as a
|
|
421
|
-
// passwordless sign-in method. rpID must be the bare host and origin
|
|
422
|
-
// the full URL — both derived from baseURL above.
|
|
423
|
-
passkey({
|
|
424
|
-
rpID: new URL(baseURL).hostname,
|
|
425
|
-
rpName: config.APP_NAME,
|
|
426
|
-
origin: baseURL
|
|
427
|
-
}),
|
|
428
|
-
// checks to see if oneTap is enabled and if google provider is available, then add the oneTap plugin.
|
|
429
|
-
// Keep this spread last: a leading spread turns `plugins` from a tuple into a plain
|
|
430
|
-
// array and better-auth 1.7 then drops plugin fields (e.g. session.impersonatedBy).
|
|
431
|
-
...config.AUTH_ENABLE_ONE_TAP && Boolean(socialProviders.google) ? [oneTap()] : []
|
|
432
|
-
]
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
var _auth;
|
|
436
|
-
function getDefaultAuth() {
|
|
437
|
-
if (!_auth) _auth = createAuth();
|
|
438
|
-
return _auth;
|
|
439
|
-
}
|
|
440
|
-
var auth = new Proxy({}, {
|
|
441
|
-
get(_target, prop) {
|
|
442
|
-
const instance = getDefaultAuth();
|
|
443
|
-
const value = Reflect.get(instance, prop);
|
|
444
|
-
return typeof value === "function" ? value.bind(instance) : value;
|
|
445
|
-
},
|
|
446
|
-
// "prop" in auth (e.g. better-auth's toNextJsHandler does `"handler" in auth`)
|
|
447
|
-
// must also see the real instance — without this it checks the empty
|
|
448
|
-
// placeholder target and always reports false.
|
|
449
|
-
has(_target, prop) {
|
|
450
|
-
return Reflect.has(getDefaultAuth(), prop);
|
|
451
|
-
},
|
|
452
|
-
ownKeys(_target) {
|
|
453
|
-
return Reflect.ownKeys(getDefaultAuth());
|
|
454
|
-
},
|
|
455
|
-
getOwnPropertyDescriptor(_target, prop) {
|
|
456
|
-
return Reflect.getOwnPropertyDescriptor(getDefaultAuth(), prop);
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
export { auth, createAuth };
|
|
461
|
-
//# sourceMappingURL=chunk-7QVIOQ47.mjs.map
|
|
462
|
-
//# sourceMappingURL=chunk-7QVIOQ47.mjs.map
|