@xk2800/nextjs-template 0.7.2-beta.1 → 0.7.2-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/components/auth/{loginErrorRecovery.tsx → forms/login-error-recovery.tsx} +1 -1
- package/components/auth/{emailPasswordLogin.tsx → forms/login-form.tsx} +8 -8
- package/components/auth/{emailPasswordSignup.tsx → forms/signup-form.tsx} +11 -8
- package/components/auth/{authCard.tsx → layout/auth-card.tsx} +5 -5
- package/components/auth/{authShell.tsx → layout/auth-shell.tsx} +17 -5
- package/components/auth/{oneTap.tsx → methods/one-tap.tsx} +2 -2
- package/components/auth/{passkeyLogin.tsx → methods/passkey-login.tsx} +2 -2
- package/components/auth/{socialLogin.tsx → methods/social-login.tsx} +3 -3
- package/components/auth/{twoFactorVerifyForm.tsx → mfa/two-factor-verify-form.tsx} +5 -5
- package/components/auth/{forgotPasswordForm.tsx → recovery/forgot-password-form.tsx} +4 -4
- package/components/auth/{resetPasswordForm.tsx → recovery/reset-password-form.tsx} +4 -4
- package/components/auth/{deviceCheck.tsx → session/device-check.tsx} +3 -3
- package/components/auth/{logoutButtons.tsx → session/logout-buttons.tsx} +2 -2
- package/components/dashboard/admin/{activityLogsSection.tsx → activity-logs/activity-logs-section.tsx} +1 -1
- package/components/dashboard/admin/activity-logs/admin-activity-logs-table.tsx +375 -0
- package/components/dashboard/admin/activity-logs/audit-severity-badge.tsx +50 -0
- package/components/dashboard/admin/activity-logs/security-highlights-collapsible.tsx +129 -0
- package/components/dashboard/admin/{adminActivityLogsSkeleton.tsx → activity-logs/skeletons/activity-logs-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{adminStatsGrid.tsx → home/admin-stats-grid.tsx} +1 -1
- package/components/dashboard/admin/{deviceThrottleCard.tsx → home/device-throttle-card.tsx} +8 -5
- package/components/dashboard/admin/{deviceThrottleTable.tsx → home/device-throttle-table.tsx} +3 -3
- package/components/dashboard/admin/{newDeviceCard.tsx → home/new-device-card.tsx} +6 -2
- package/components/dashboard/admin/{newDeviceTable.tsx → home/new-device-table.tsx} +4 -4
- package/components/dashboard/admin/{sharedDeviceCard.tsx → home/shared-device-card.tsx} +3 -3
- package/components/dashboard/admin/{sharedDeviceTable.tsx → home/shared-device-table.tsx} +3 -3
- package/components/dashboard/admin/{adminStatsGridSkeleton.tsx → home/skeletons/admin-stats-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{broadcastActions.tsx → marketing/broadcast-actions.tsx} +3 -3
- package/components/dashboard/admin/{confirmSendDialog.tsx → marketing/confirm-send-dialog.tsx} +1 -1
- package/components/dashboard/admin/{marketingEmailForm.tsx → marketing/marketing-email-form.tsx} +7 -7
- package/components/dashboard/admin/{marketingSection.tsx → marketing/marketing-section.tsx} +6 -6
- package/components/dashboard/admin/{subscribersCard.tsx → marketing/subscribers-card.tsx} +3 -3
- package/components/dashboard/admin/{feedbackTestForm.tsx → system-settings/feedback-test-form.tsx} +4 -4
- package/components/dashboard/admin/{systemSettingsSkeleton.tsx → system-settings/skeletons/system-settings-skeleton.tsx} +2 -2
- package/components/dashboard/admin/system-settings/system-settings-form.tsx +362 -0
- package/components/dashboard/admin/{systemSettingsSection.tsx → system-settings/system-settings-section.tsx} +3 -2
- package/components/dashboard/admin/users/admin-user-actions.tsx +238 -0
- package/components/dashboard/admin/users/admin-user-profile-card.tsx +70 -0
- package/components/dashboard/admin/users/admin-user-security-card.tsx +47 -0
- package/components/dashboard/admin/users/admin-user-status-card.tsx +89 -0
- package/components/dashboard/admin/{adminUsersTable.tsx → users/admin-users-table.tsx} +129 -132
- package/components/dashboard/admin/{adminUserActivityLogCard.tsx → users/detail/admin-user-activity-log-card.tsx} +3 -3
- package/components/dashboard/admin/{adminUserActivityLogTable.tsx → users/detail/admin-user-activity-log-table.tsx} +3 -3
- package/components/dashboard/admin/{adminUserConsentCard.tsx → users/detail/admin-user-consent-card.tsx} +4 -4
- package/components/dashboard/admin/{adminUserDevicesCard.tsx → users/detail/admin-user-devices-card.tsx} +2 -2
- package/components/dashboard/admin/{adminUserLoginInfoCard.tsx → users/detail/admin-user-login-info-card.tsx} +3 -3
- package/components/dashboard/admin/{adminUserLoginInfoTable.tsx → users/detail/admin-user-login-info-table.tsx} +3 -3
- package/components/dashboard/admin/{adminUserSessionsCard.tsx → users/detail/admin-user-sessions-card.tsx} +5 -5
- package/components/dashboard/admin/{impersonationLogCard.tsx → users/impersonation-log-card.tsx} +10 -5
- package/components/dashboard/admin/users/impersonation-tab.tsx +255 -0
- package/components/dashboard/admin/users/invite-user-dialog.tsx +80 -0
- package/components/dashboard/admin/{revokeAllSessionsButton.tsx → users/revoke-all-sessions.tsx} +5 -3
- package/components/dashboard/admin/{adminUsersSkeleton.tsx → users/skeletons/admin-users-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{usersSection.tsx → users/users-section.tsx} +1 -1
- package/components/dashboard/{errorFeedback.tsx → common/error-feedback.tsx} +1 -1
- package/components/dashboard/{feedbackDialog.tsx → common/feedback-dialog.tsx} +4 -4
- package/components/dashboard/{sectionErrorFallback.tsx → common/section-error-fallback.tsx} +1 -1
- package/components/dashboard/{verifyEmailButton.tsx → common/verify-email-button.tsx} +2 -2
- package/components/dashboard/{appSidebar.tsx → layout/app-sidebar.tsx} +11 -8
- package/components/dashboard/{dashboardHeader.tsx → layout/dashboard-header.tsx} +1 -1
- package/components/dashboard/{impersonationBanner.tsx → layout/impersonation-banner.tsx} +2 -2
- package/components/dashboard/layout/mobile-nav.tsx +95 -0
- package/components/dashboard/{navStyleToggle.tsx → layout/nav-style-toggle.tsx} +1 -1
- package/components/dashboard/{topNav.tsx → layout/top-nav.tsx} +19 -38
- package/components/dashboard/{installAppCard.tsx → overview/install-app-card.tsx} +2 -2
- package/components/dashboard/{accountDetailsCard.tsx → settings/account-details-card.tsx} +5 -5
- package/components/dashboard/{activityLogsCard.tsx → settings/activity-logs-card.tsx} +6 -6
- package/components/dashboard/{activityLogsSection.tsx → settings/activity-logs-section.tsx} +1 -1
- package/components/dashboard/{adminSection.tsx → settings/admin-section.tsx} +2 -2
- package/components/dashboard/{deleteAccountCard.tsx → settings/delete-account-card.tsx} +7 -7
- package/components/dashboard/{marketingUpdatesCard.tsx → settings/marketing-updates-card.tsx} +3 -3
- package/components/dashboard/{marketingUpdatesSection.tsx → settings/marketing-updates-section.tsx} +1 -1
- package/components/dashboard/{passkeysCard.tsx → settings/passkeys-card.tsx} +8 -8
- package/components/dashboard/{profileCard.tsx → settings/profile-card.tsx} +4 -4
- package/components/dashboard/{sessionsCard.tsx → settings/sessions/sessions-card.tsx} +6 -6
- package/components/dashboard/{sessionsSection.tsx → settings/sessions/sessions-section.tsx} +1 -1
- package/components/dashboard/{sessionsCardSkeleton.tsx → settings/sessions/skeletons/sessions-card-skeleton.tsx} +2 -2
- package/components/dashboard/{activityLogsCardSkeleton.tsx → settings/skeletons/activity-logs-card-skeleton.tsx} +2 -2
- package/components/dashboard/{twoFactorCard.tsx → settings/two-factor-card.tsx} +8 -8
- package/components/email/team/workspace-invite.tsx +51 -0
- package/components/email/{send-email-button.tsx → ui/send-email-button.tsx} +1 -1
- package/components/error-boundary.tsx +32 -0
- package/components/settings/appearance/appearance-section.tsx +64 -0
- package/components/settings/index.ts +5 -0
- package/components/settings/notifications/notifications-section.tsx +31 -0
- package/components/settings/profile/profile-section.tsx +38 -0
- package/components/settings/security/security-section.tsx +24 -0
- package/components/settings/settings-nav.tsx +35 -0
- package/components/site/{cookie-banner.tsx → compliance/cookie-banner.tsx} +6 -6
- package/components/site/push/push-notifications-card.tsx +117 -0
- package/components/ui/collapsible.tsx +9 -0
- package/components/ui/column-picker.tsx +1 -1
- package/components/ui/data-table.tsx +1 -1
- package/components/ui/dialog.tsx +46 -13
- package/components/ui/drawer.tsx +88 -0
- package/components/ui/tabs.tsx +52 -0
- package/dist/activity/logger.d.mts +2 -1
- package/dist/activity/logger.d.ts +2 -1
- package/dist/activity/logger.js +66 -15
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +32 -21
- package/dist/activity/queries.d.ts +32 -21
- package/dist/activity/queries.js +86 -22
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +27 -14
- package/dist/activity/queries.mjs.map +1 -1
- package/dist/admin/queries.d.mts +2 -1
- package/dist/admin/queries.d.ts +2 -1
- package/dist/admin/queries.js +48 -17
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +9 -9
- package/dist/admin/queries.mjs.map +1 -1
- package/dist/api/feedback.js +302 -248
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +14 -12
- package/dist/api/feedback.mjs.map +1 -1
- package/dist/api/marketing.js +320 -266
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +16 -25
- package/dist/api/marketing.mjs.map +1 -1
- package/dist/auth/helpers.d.mts +60 -18
- package/dist/auth/helpers.d.ts +60 -18
- package/dist/auth/helpers.js +332 -267
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +9 -9
- package/dist/auth/index.d.mts +86 -47
- package/dist/auth/index.d.ts +86 -47
- package/dist/auth/index.js +296 -244
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +8 -8
- package/dist/auth-client/index.d.mts +1215 -2527
- package/dist/auth-client/index.d.ts +1215 -2527
- package/dist/auth-client/index.js +37 -3
- package/dist/auth-client/index.js.map +1 -1
- package/dist/auth-client/index.mjs +19 -3
- package/dist/auth-client/index.mjs.map +1 -1
- package/dist/{chunk-TE5BEAQB.mjs → chunk-3BH6BVBQ.mjs} +17 -7
- package/dist/chunk-3BH6BVBQ.mjs.map +1 -0
- package/dist/chunk-D56ENLSX.mjs +6 -0
- package/dist/chunk-D56ENLSX.mjs.map +1 -0
- package/dist/{chunk-HUEDEAY3.mjs → chunk-DCPVEZS7.mjs} +14 -4
- package/dist/chunk-DCPVEZS7.mjs.map +1 -0
- package/dist/{chunk-NQELV53D.mjs → chunk-DWLMCMXF.mjs} +4 -4
- package/dist/chunk-DWLMCMXF.mjs.map +1 -0
- package/dist/{chunk-653GF7OT.mjs → chunk-EXMUANQ3.mjs} +4 -4
- package/dist/chunk-EXMUANQ3.mjs.map +1 -0
- package/dist/chunk-LADVCLEQ.mjs +43 -0
- package/dist/chunk-LADVCLEQ.mjs.map +1 -0
- package/dist/{chunk-2BJ3B4FR.mjs → chunk-NJBRKKLK.mjs} +46 -7
- package/dist/chunk-NJBRKKLK.mjs.map +1 -0
- package/dist/{chunk-6OAHCEDJ.mjs → chunk-QDUPSU5O.mjs} +5 -5
- package/dist/chunk-QDUPSU5O.mjs.map +1 -0
- package/dist/{chunk-H3XZTZ5K.mjs → chunk-RK2B5AOQ.mjs} +41 -29
- package/dist/chunk-RK2B5AOQ.mjs.map +1 -0
- package/dist/{chunk-L242CZ64.mjs → chunk-TIR7KHXL.mjs} +3 -3
- package/dist/chunk-TIR7KHXL.mjs.map +1 -0
- package/dist/{chunk-O5EQYHNC.mjs → chunk-ZOQHHFYA.mjs} +7 -4
- package/dist/chunk-ZOQHHFYA.mjs.map +1 -0
- package/dist/{chunk-EIS4SCQW.mjs → chunk-ZQTI4T2K.mjs} +231 -220
- package/dist/chunk-ZQTI4T2K.mjs.map +1 -0
- package/dist/config/env.d.mts +3 -0
- package/dist/config/env.d.ts +3 -0
- package/dist/config/env.js +12 -2
- package/dist/config/env.js.map +1 -1
- package/dist/config/env.mjs +1 -1
- package/dist/db/index.d.mts +3 -7
- package/dist/db/index.d.ts +3 -7
- package/dist/db/index.js +61 -12
- 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 -4
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.d.mts +2 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.js +62 -13
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.d.mts +4 -3
- package/dist/marketing/index.d.ts +4 -3
- package/dist/marketing/index.js +14 -4
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{email-template-passkey-change-F5Q2SXHD.mjs → passkey-changed-KEGNTIPE.mjs} +2 -2
- package/dist/passkey-changed-KEGNTIPE.mjs.map +1 -0
- package/dist/{email-template-reset-password-QTCQNXOD.mjs → reset-password-64VQEXBW.mjs} +2 -2
- package/dist/reset-password-64VQEXBW.mjs.map +1 -0
- package/dist/{schema-DzC5zdOq.d.mts → schema-BujGgvAy.d.mts} +35 -2
- package/dist/{schema-DzC5zdOq.d.ts → schema-BujGgvAy.d.ts} +35 -2
- package/dist/sessions/queries.js +61 -12
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/sessions/queries.mjs.map +1 -1
- package/dist/settings/queries.d.mts +11 -2
- package/dist/settings/queries.d.ts +11 -2
- package/dist/settings/queries.js +84 -13
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +41 -21
- package/dist/users/queries.d.ts +41 -21
- package/dist/users/queries.js +117 -23
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +57 -17
- package/dist/users/queries.mjs.map +1 -1
- package/dist/{email-template-verify-email-WZDCCAKK.mjs → verify-email-4KMNGDKN.mjs} +2 -2
- package/dist/verify-email-4KMNGDKN.mjs.map +1 -0
- package/lib/{auth-client.ts → auth/client.ts} +22 -2
- package/lib/push/client.ts +39 -0
- package/lib/security/activity-severity.ts +57 -0
- package/lib/{request-info.ts → utils/request-info.ts} +7 -3
- package/package.json +177 -75
- package/scripts/check-deps.mjs +68 -0
- package/components/dashboard/admin/adminActivityLogsTable.tsx +0 -323
- package/components/dashboard/admin/adminUserStatusCard.tsx +0 -57
- package/components/dashboard/admin/systemSettingsForm.tsx +0 -289
- package/dist/chunk-2BJ3B4FR.mjs.map +0 -1
- package/dist/chunk-653GF7OT.mjs.map +0 -1
- package/dist/chunk-6OAHCEDJ.mjs.map +0 -1
- package/dist/chunk-EIS4SCQW.mjs.map +0 -1
- package/dist/chunk-H3XZTZ5K.mjs.map +0 -1
- package/dist/chunk-HUEDEAY3.mjs.map +0 -1
- package/dist/chunk-K62JYJRR.mjs +0 -30
- package/dist/chunk-K62JYJRR.mjs.map +0 -1
- package/dist/chunk-L242CZ64.mjs.map +0 -1
- package/dist/chunk-NQELV53D.mjs.map +0 -1
- package/dist/chunk-O5EQYHNC.mjs.map +0 -1
- package/dist/chunk-TE5BEAQB.mjs.map +0 -1
- package/dist/email-template-passkey-change-F5Q2SXHD.mjs.map +0 -1
- package/dist/email-template-reset-password-QTCQNXOD.mjs.map +0 -1
- package/dist/email-template-verify-email-WZDCCAKK.mjs.map +0 -1
- /package/components/dashboard/{heartbeat.tsx → common/heartbeat.tsx} +0 -0
- /package/components/email/{email-template-reset-password.tsx → auth/reset-password.tsx} +0 -0
- /package/components/email/{email-template-verify-email.tsx → auth/verify-email.tsx} +0 -0
- /package/components/email/{email-template-welcome.tsx → auth/welcome.tsx} +0 -0
- /package/components/email/{email-template.tsx → layout/base-layout.tsx} +0 -0
- /package/components/email/{email-template-2.tsx → marketing/general-announcement.tsx} +0 -0
- /package/components/email/{email-template-banned.tsx → security/account-banned.tsx} +0 -0
- /package/components/email/{email-template-new-device.tsx → security/new-device-alert.tsx} +0 -0
- /package/components/email/{email-template-passkey-change.tsx → security/passkey-changed.tsx} +0 -0
- /package/lib/{maintenance.ts → config/maintenance.ts} +0 -0
- /package/lib/{cookie-consent.ts → security/cookie-consent.ts} +0 -0
- /package/lib/{cookie-names.ts → security/cookie-names.ts} +0 -0
- /package/lib/{device-fingerprint.ts → security/device-fingerprint.ts} +0 -0
- /package/lib/{formatters.ts → utils/formatters.ts} +0 -0
- /package/lib/{recalculate-columns.ts → utils/recalculate-columns.ts} +0 -0
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { logActivity } from './chunk-
|
|
2
|
-
import { getClientIp, formatLocation, lookupGeoLocation, formatDeviceInfo, parseUserAgent, WINDOW_MS, isOverLimit, MAX_IP, RETENTION_MS } from './chunk-
|
|
3
|
-
import { getEffectiveAuthFlags } from './chunk-
|
|
4
|
-
import { getResend, EMAIL_FROM } from './chunk-
|
|
5
|
-
import { db } from './chunk-
|
|
6
|
-
import { users, passkeys, twoFactors, verifications, sessions, accounts, authThrottle } from './chunk-
|
|
7
|
-
import { config } from './chunk-
|
|
1
|
+
import { logActivity } from './chunk-ZOQHHFYA.mjs';
|
|
2
|
+
import { getClientIp, formatLocation, lookupGeoLocation, formatDeviceInfo, parseUserAgent, WINDOW_MS, isOverLimit, MAX_IP, RETENTION_MS } from './chunk-QDUPSU5O.mjs';
|
|
3
|
+
import { getEffectiveAuthFlags } from './chunk-NJBRKKLK.mjs';
|
|
4
|
+
import { getResend, EMAIL_FROM } from './chunk-TIR7KHXL.mjs';
|
|
5
|
+
import { db } from './chunk-LADVCLEQ.mjs';
|
|
6
|
+
import { users, passkeys, twoFactors, verifications, sessions, accounts, authThrottle } from './chunk-3BH6BVBQ.mjs';
|
|
7
|
+
import { config } from './chunk-DCPVEZS7.mjs';
|
|
8
8
|
import { __spreadValues, __spreadProps } from './chunk-3465SI5N.mjs';
|
|
9
9
|
import 'server-only';
|
|
10
|
+
import { execFile } from 'child_process';
|
|
11
|
+
import { existsSync } from 'fs';
|
|
12
|
+
import { join } from 'path';
|
|
10
13
|
import { betterAuth } from 'better-auth';
|
|
11
14
|
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
|
|
12
15
|
import { createId } from '@paralleldrive/cuid2';
|
|
@@ -16,15 +19,25 @@ import { createAuthMiddleware, APIError, getSessionFromCtx } from 'better-auth/a
|
|
|
16
19
|
import { symmetricDecrypt } from 'better-auth/crypto';
|
|
17
20
|
import { passkey } from '@better-auth/passkey';
|
|
18
21
|
|
|
22
|
+
// node_modules/@better-auth/utils/dist/bytes.mjs
|
|
23
|
+
function toBufferSource(data) {
|
|
24
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
25
|
+
if (!ArrayBuffer.isView(data)) return data;
|
|
26
|
+
if (data.buffer instanceof ArrayBuffer) return data;
|
|
27
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
|
|
28
|
+
}
|
|
29
|
+
function toUint8Array(data) {
|
|
30
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
31
|
+
return new Uint8Array(data);
|
|
32
|
+
}
|
|
33
|
+
|
|
19
34
|
// node_modules/@better-auth/utils/dist/base32.mjs
|
|
20
35
|
function getAlphabet(hex2) {
|
|
21
36
|
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
22
37
|
}
|
|
23
38
|
function createDecodeMap(alphabet) {
|
|
24
39
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
25
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
26
|
-
decodeMap.set(alphabet[i], i);
|
|
27
|
-
}
|
|
40
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
28
41
|
return decodeMap;
|
|
29
42
|
}
|
|
30
43
|
function base32Encode(data, alphabet, padding) {
|
|
@@ -39,9 +52,7 @@ function base32Encode(data, alphabet, padding) {
|
|
|
39
52
|
result += alphabet[buffer >> shift & 31];
|
|
40
53
|
}
|
|
41
54
|
}
|
|
42
|
-
if (shift > 0)
|
|
43
|
-
result += alphabet[buffer << 5 - shift & 31];
|
|
44
|
-
}
|
|
55
|
+
if (shift > 0) result += alphabet[buffer << 5 - shift & 31];
|
|
45
56
|
if (padding) {
|
|
46
57
|
const padCount = (8 - result.length % 8) % 8;
|
|
47
58
|
result += "=".repeat(padCount);
|
|
@@ -54,12 +65,9 @@ function base32Decode(data, alphabet) {
|
|
|
54
65
|
let buffer = 0;
|
|
55
66
|
let bitsCollected = 0;
|
|
56
67
|
for (const char of data) {
|
|
57
|
-
if (char === "=")
|
|
58
|
-
break;
|
|
68
|
+
if (char === "=") break;
|
|
59
69
|
const value = decodeMap.get(char);
|
|
60
|
-
if (value === void 0) {
|
|
61
|
-
throw new Error(`Invalid Base32 character: ${char}`);
|
|
62
|
-
}
|
|
70
|
+
if (value === void 0) throw new Error(`Invalid Base32 character: ${char}`);
|
|
63
71
|
buffer = buffer << 5 | value;
|
|
64
72
|
bitsCollected += 5;
|
|
65
73
|
while (bitsCollected >= 8) {
|
|
@@ -71,68 +79,34 @@ function base32Decode(data, alphabet) {
|
|
|
71
79
|
}
|
|
72
80
|
var base32 = {
|
|
73
81
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
* Encodes data into a Base32 string.
|
|
83
|
+
* @param data - The data to encode (ArrayBuffer, number-based TypedArray, or string).
|
|
84
|
+
* @param options - Encoding options.
|
|
85
|
+
* @returns The Base32 encoded string.
|
|
86
|
+
*/
|
|
79
87
|
encode(data, options = {}) {
|
|
80
88
|
var _a;
|
|
81
89
|
const alphabet = getAlphabet();
|
|
82
|
-
|
|
83
|
-
return base32Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
90
|
+
return base32Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
84
91
|
},
|
|
85
92
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
94
|
+
* @param data - The Base32 encoded string or ArrayBuffer/TypedArray.
|
|
95
|
+
* @returns The decoded Uint8Array.
|
|
96
|
+
*/
|
|
90
97
|
decode(data) {
|
|
91
|
-
if (typeof data !== "string")
|
|
92
|
-
data = new TextDecoder().decode(data);
|
|
93
|
-
}
|
|
98
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
94
99
|
const alphabet = getAlphabet();
|
|
95
100
|
return base32Decode(data, alphabet);
|
|
96
101
|
}
|
|
97
102
|
};
|
|
98
103
|
|
|
99
|
-
// node_modules/@better-auth/utils/dist/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
if (data.byteLength === 0) {
|
|
107
|
-
return "";
|
|
108
|
-
}
|
|
109
|
-
const buffer = new Uint8Array(data);
|
|
110
|
-
let result = "";
|
|
111
|
-
for (const byte of buffer) {
|
|
112
|
-
result += byte.toString(16).padStart(2, "0");
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
115
|
-
},
|
|
116
|
-
decode: (data) => {
|
|
117
|
-
if (!data) {
|
|
118
|
-
return "";
|
|
119
|
-
}
|
|
120
|
-
if (typeof data === "string") {
|
|
121
|
-
if (data.length % 2 !== 0) {
|
|
122
|
-
throw new Error("Invalid hexadecimal string");
|
|
123
|
-
}
|
|
124
|
-
if (!new RegExp(`^[${hexadecimal}]+$`).test(data)) {
|
|
125
|
-
throw new Error("Invalid hexadecimal string");
|
|
126
|
-
}
|
|
127
|
-
const result = new Uint8Array(data.length / 2);
|
|
128
|
-
for (let i = 0; i < data.length; i += 2) {
|
|
129
|
-
result[i / 2] = parseInt(data.slice(i, i + 2), 16);
|
|
130
|
-
}
|
|
131
|
-
return new TextDecoder().decode(result);
|
|
132
|
-
}
|
|
133
|
-
return new TextDecoder().decode(data);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
104
|
+
// node_modules/@better-auth/utils/dist/index.mjs
|
|
105
|
+
function getWebcryptoSubtle() {
|
|
106
|
+
const cr = typeof globalThis !== "undefined" && globalThis.crypto;
|
|
107
|
+
if (cr && typeof cr.subtle === "object" && cr.subtle != null) return cr.subtle;
|
|
108
|
+
throw new Error("crypto.subtle must be defined");
|
|
109
|
+
}
|
|
136
110
|
|
|
137
111
|
// node_modules/@better-auth/utils/dist/base64.mjs
|
|
138
112
|
function getAlphabet2(urlSafe) {
|
|
@@ -150,9 +124,7 @@ function base64Encode(data, alphabet, padding) {
|
|
|
150
124
|
result += alphabet[buffer >> shift & 63];
|
|
151
125
|
}
|
|
152
126
|
}
|
|
153
|
-
if (shift > 0)
|
|
154
|
-
result += alphabet[buffer << 6 - shift & 63];
|
|
155
|
-
}
|
|
127
|
+
if (shift > 0) result += alphabet[buffer << 6 - shift & 63];
|
|
156
128
|
if (padding) {
|
|
157
129
|
const padCount = (4 - result.length % 4) % 4;
|
|
158
130
|
result += "=".repeat(padCount);
|
|
@@ -161,19 +133,14 @@ function base64Encode(data, alphabet, padding) {
|
|
|
161
133
|
}
|
|
162
134
|
function base64Decode(data, alphabet) {
|
|
163
135
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
164
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
165
|
-
decodeMap.set(alphabet[i], i);
|
|
166
|
-
}
|
|
136
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
167
137
|
const result = [];
|
|
168
138
|
let buffer = 0;
|
|
169
139
|
let bitsCollected = 0;
|
|
170
140
|
for (const char of data) {
|
|
171
|
-
if (char === "=")
|
|
172
|
-
break;
|
|
141
|
+
if (char === "=") break;
|
|
173
142
|
const value = decodeMap.get(char);
|
|
174
|
-
if (value === void 0) {
|
|
175
|
-
throw new Error(`Invalid Base64 character: ${char}`);
|
|
176
|
-
}
|
|
143
|
+
if (value === void 0) throw new Error(`Invalid Base64 character: ${char}`);
|
|
177
144
|
buffer = buffer << 6 | value;
|
|
178
145
|
bitsCollected += 6;
|
|
179
146
|
if (bitsCollected >= 8) {
|
|
@@ -187,15 +154,11 @@ var base64 = {
|
|
|
187
154
|
encode(data, options = {}) {
|
|
188
155
|
var _a;
|
|
189
156
|
const alphabet = getAlphabet2(false);
|
|
190
|
-
|
|
191
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
157
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
192
158
|
},
|
|
193
159
|
decode(data) {
|
|
194
|
-
if (typeof data !== "string")
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
const urlSafe = data.includes("-") || data.includes("_");
|
|
198
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
160
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
161
|
+
const alphabet = getAlphabet2(data.includes("-") || data.includes("_"));
|
|
199
162
|
return base64Decode(data, alphabet);
|
|
200
163
|
}
|
|
201
164
|
};
|
|
@@ -203,152 +166,142 @@ var base64Url = {
|
|
|
203
166
|
encode(data, options = {}) {
|
|
204
167
|
var _a;
|
|
205
168
|
const alphabet = getAlphabet2(true);
|
|
206
|
-
|
|
207
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
169
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
208
170
|
},
|
|
209
171
|
decode(data) {
|
|
210
|
-
|
|
211
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
212
|
-
return base64Decode(data, alphabet);
|
|
172
|
+
return base64Decode(data, getAlphabet2(data.includes("-") || data.includes("_")));
|
|
213
173
|
}
|
|
214
174
|
};
|
|
215
175
|
|
|
216
|
-
// node_modules/@
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
176
|
+
// node_modules/@noble/hashes/utils.js
|
|
177
|
+
var hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
178
|
+
// @ts-ignore
|
|
179
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
180
|
+
))();
|
|
181
|
+
function asciiToBase16(ch) {
|
|
182
|
+
return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
|
|
183
|
+
}
|
|
184
|
+
function hexToBytes(hex2) {
|
|
185
|
+
if (typeof hex2 !== "string")
|
|
186
|
+
throw new TypeError("hex string expected, got " + typeof hex2);
|
|
187
|
+
if (hasHexBuiltin) {
|
|
188
|
+
try {
|
|
189
|
+
return Uint8Array.fromHex(hex2);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
if (error instanceof SyntaxError)
|
|
192
|
+
throw new RangeError(error.message);
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const hl = hex2.length;
|
|
197
|
+
const al = hl / 2;
|
|
198
|
+
if (hl % 2)
|
|
199
|
+
throw new RangeError("hex string expected, got unpadded hex of length " + hl);
|
|
200
|
+
const array = new Uint8Array(al);
|
|
201
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
202
|
+
const n1 = asciiToBase16(hex2.charCodeAt(hi));
|
|
203
|
+
const n2 = asciiToBase16(hex2.charCodeAt(hi + 1));
|
|
204
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
205
|
+
const char = hex2[hi] + hex2[hi + 1];
|
|
206
|
+
throw new RangeError('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
207
|
+
}
|
|
208
|
+
array[ai] = n1 * 16 + n2;
|
|
209
|
+
}
|
|
210
|
+
return array;
|
|
222
211
|
}
|
|
223
212
|
|
|
213
|
+
// node_modules/@better-auth/utils/dist/hex.mjs
|
|
214
|
+
var toBytes = (data) => hexToBytes(data);
|
|
215
|
+
var hex = {
|
|
216
|
+
encode: (data) => {
|
|
217
|
+
const buffer = toUint8Array(data);
|
|
218
|
+
if (buffer.byteLength === 0) return "";
|
|
219
|
+
let result = "";
|
|
220
|
+
for (const byte of buffer) result += byte.toString(16).padStart(2, "0");
|
|
221
|
+
return result;
|
|
222
|
+
},
|
|
223
|
+
decode: (data) => {
|
|
224
|
+
if (!data) return "";
|
|
225
|
+
if (typeof data === "string") return new TextDecoder().decode(toBytes(data));
|
|
226
|
+
return new TextDecoder().decode(data);
|
|
227
|
+
},
|
|
228
|
+
toBytes
|
|
229
|
+
};
|
|
230
|
+
|
|
224
231
|
// node_modules/@better-auth/utils/dist/hmac.mjs
|
|
225
232
|
var createHMAC = (algorithm = "SHA-256", encoding = "none") => {
|
|
226
|
-
const
|
|
233
|
+
const hmac2 = {
|
|
227
234
|
importKey: async (key, keyUsage) => {
|
|
228
|
-
return getWebcryptoSubtle().importKey(
|
|
229
|
-
"
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
false,
|
|
233
|
-
[keyUsage]
|
|
234
|
-
);
|
|
235
|
+
return getWebcryptoSubtle().importKey("raw", toBufferSource(key), {
|
|
236
|
+
name: "HMAC",
|
|
237
|
+
hash: { name: algorithm }
|
|
238
|
+
}, false, [keyUsage]);
|
|
235
239
|
},
|
|
236
240
|
sign: async (hmacKey, data) => {
|
|
237
|
-
if (typeof hmacKey === "string")
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
hmacKey,
|
|
243
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
244
|
-
);
|
|
245
|
-
if (encoding === "hex") {
|
|
246
|
-
return hex.encode(signature);
|
|
247
|
-
}
|
|
248
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
249
|
-
return base64Url.encode(signature, {
|
|
250
|
-
padding: encoding !== "base64urlnopad"
|
|
251
|
-
});
|
|
252
|
-
}
|
|
241
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "sign");
|
|
242
|
+
const signature = await getWebcryptoSubtle().sign("HMAC", hmacKey, toBufferSource(data));
|
|
243
|
+
if (encoding === "hex") return hex.encode(signature);
|
|
244
|
+
if (encoding === "base64") return base64.encode(signature);
|
|
245
|
+
if (encoding === "base64url" || encoding === "base64urlnopad") return base64Url.encode(signature, { padding: encoding !== "base64urlnopad" });
|
|
253
246
|
return signature;
|
|
254
247
|
},
|
|
255
248
|
verify: async (hmacKey, data, signature) => {
|
|
256
|
-
if (typeof hmacKey === "string")
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
signature = hex.decode(signature);
|
|
261
|
-
}
|
|
262
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
263
|
-
signature = await base64.decode(signature);
|
|
264
|
-
}
|
|
265
|
-
return getWebcryptoSubtle().verify(
|
|
266
|
-
"HMAC",
|
|
267
|
-
hmacKey,
|
|
268
|
-
typeof signature === "string" ? new TextEncoder().encode(signature) : signature,
|
|
269
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
270
|
-
);
|
|
249
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "verify");
|
|
250
|
+
if (encoding === "hex") signature = typeof signature === "string" ? hex.toBytes(signature) : signature;
|
|
251
|
+
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") signature = await base64.decode(signature);
|
|
252
|
+
return getWebcryptoSubtle().verify("HMAC", hmacKey, toBufferSource(signature), toBufferSource(data));
|
|
271
253
|
}
|
|
272
254
|
};
|
|
273
|
-
return
|
|
255
|
+
return hmac2;
|
|
274
256
|
};
|
|
275
257
|
|
|
276
258
|
// node_modules/@better-auth/utils/dist/otp.mjs
|
|
277
259
|
var defaultPeriod = 30;
|
|
278
260
|
var defaultDigits = 6;
|
|
261
|
+
var hmac = createHMAC("SHA-1");
|
|
279
262
|
function constantTimeEqualOTP(input, expected) {
|
|
280
263
|
let difference = input.length ^ expected.length;
|
|
281
|
-
for (let i = 0; i < expected.length; i++)
|
|
282
|
-
difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
283
|
-
}
|
|
264
|
+
for (let i = 0; i < expected.length; i++) difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
284
265
|
return difference === 0;
|
|
285
266
|
}
|
|
286
|
-
async function generateHOTP(
|
|
287
|
-
counter,
|
|
288
|
-
digits,
|
|
289
|
-
hash = "SHA-1"
|
|
290
|
-
}) {
|
|
267
|
+
async function generateHOTP(key, { counter, digits }) {
|
|
291
268
|
const _digits = digits != null ? digits : defaultDigits;
|
|
292
|
-
if (_digits < 1 || _digits > 8)
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
const buffer = new ArrayBuffer(8);
|
|
269
|
+
if (_digits < 1 || _digits > 8) throw new TypeError("Digits must be between 1 and 8");
|
|
270
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
296
271
|
new DataView(buffer).setBigUint64(0, BigInt(counter), false);
|
|
297
272
|
const bytes = new Uint8Array(buffer);
|
|
298
|
-
const
|
|
273
|
+
const signature = await hmac.sign(key, bytes);
|
|
274
|
+
const hmacResult = new Uint8Array(signature);
|
|
299
275
|
const offset = hmacResult[hmacResult.length - 1] & 15;
|
|
300
|
-
|
|
301
|
-
const otp = truncated % 10 ** _digits;
|
|
302
|
-
return otp.toString().padStart(_digits, "0");
|
|
276
|
+
return (((hmacResult[offset] & 127) << 24 | (hmacResult[offset + 1] & 255) << 16 | (hmacResult[offset + 2] & 255) << 8 | hmacResult[offset + 3] & 255) % 10 ** _digits).toString().padStart(_digits, "0");
|
|
303
277
|
}
|
|
304
|
-
async function generateTOTP(
|
|
278
|
+
async function generateTOTP(key, options) {
|
|
305
279
|
var _a, _b;
|
|
306
280
|
const digits = (_a = options == null ? void 0 : options.digits) != null ? _a : defaultDigits;
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
281
|
+
const milliseconds = ((_b = options == null ? void 0 : options.period) != null ? _b : defaultPeriod) * 1e3;
|
|
282
|
+
return await generateHOTP(key, {
|
|
283
|
+
counter: Math.floor(Date.now() / milliseconds),
|
|
284
|
+
digits
|
|
285
|
+
});
|
|
311
286
|
}
|
|
312
|
-
async function verifyTOTP(otp, {
|
|
313
|
-
window = 1,
|
|
314
|
-
digits = defaultDigits,
|
|
315
|
-
secret,
|
|
316
|
-
period = defaultPeriod
|
|
317
|
-
}) {
|
|
287
|
+
async function verifyTOTP(otp, { window = 1, digits = defaultDigits, key, period = defaultPeriod }) {
|
|
318
288
|
const milliseconds = period * 1e3;
|
|
319
289
|
const counter = Math.floor(Date.now() / milliseconds);
|
|
320
290
|
let matched = false;
|
|
321
|
-
for (let i = -window; i <= window; i++) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
});
|
|
326
|
-
matched = constantTimeEqualOTP(otp, generatedOTP) || matched;
|
|
327
|
-
}
|
|
291
|
+
for (let i = -window; i <= window; i++) matched = constantTimeEqualOTP(otp, await generateHOTP(key, {
|
|
292
|
+
counter: counter + i,
|
|
293
|
+
digits
|
|
294
|
+
})) || matched;
|
|
328
295
|
return matched;
|
|
329
296
|
}
|
|
330
|
-
function generateQRCode({
|
|
331
|
-
issuer
|
|
332
|
-
account,
|
|
333
|
-
secret,
|
|
334
|
-
digits = defaultDigits,
|
|
335
|
-
period = defaultPeriod
|
|
336
|
-
}) {
|
|
337
|
-
const encodedIssuer = encodeURIComponent(issuer);
|
|
338
|
-
const encodedAccountName = encodeURIComponent(account);
|
|
339
|
-
const baseURI = `otpauth://totp/${encodedIssuer}:${encodedAccountName}`;
|
|
297
|
+
function generateQRCode({ issuer, account, secret, digits = defaultDigits, period = defaultPeriod }) {
|
|
298
|
+
const baseURI = `otpauth://totp/${encodeURIComponent(issuer)}:${encodeURIComponent(account)}`;
|
|
340
299
|
const params = new URLSearchParams({
|
|
341
|
-
secret: base32.encode(secret, {
|
|
342
|
-
padding: false
|
|
343
|
-
}),
|
|
300
|
+
secret: base32.encode(secret, { padding: false }),
|
|
344
301
|
issuer
|
|
345
302
|
});
|
|
346
|
-
if (digits !== void 0)
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
if (period !== void 0) {
|
|
350
|
-
params.set("period", period.toString());
|
|
351
|
-
}
|
|
303
|
+
if (digits !== void 0) params.set("digits", digits.toString());
|
|
304
|
+
if (period !== void 0) params.set("period", period.toString());
|
|
352
305
|
return `${baseURI}?${params.toString()}`;
|
|
353
306
|
}
|
|
354
307
|
var createOTP = (secret, opts) => {
|
|
@@ -356,14 +309,38 @@ var createOTP = (secret, opts) => {
|
|
|
356
309
|
const digits = (_a = void 0 ) != null ? _a : defaultDigits;
|
|
357
310
|
const period = (_b = void 0 ) != null ? _b : defaultPeriod;
|
|
358
311
|
return {
|
|
359
|
-
hotp: (counter) =>
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
312
|
+
hotp: async (counter) => {
|
|
313
|
+
return generateHOTP(await hmac.importKey(secret, "sign"), {
|
|
314
|
+
counter,
|
|
315
|
+
digits
|
|
316
|
+
});
|
|
317
|
+
},
|
|
318
|
+
totp: async () => {
|
|
319
|
+
return generateTOTP(await hmac.importKey(secret, "sign"), {
|
|
320
|
+
digits,
|
|
321
|
+
period
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
verify: async (otp, options) => {
|
|
325
|
+
return verifyTOTP(otp, __spreadValues({
|
|
326
|
+
key: await hmac.importKey(secret, "sign"),
|
|
327
|
+
digits,
|
|
328
|
+
period
|
|
329
|
+
}, options));
|
|
330
|
+
},
|
|
331
|
+
url: (issuer, account) => {
|
|
332
|
+
return generateQRCode({
|
|
333
|
+
issuer,
|
|
334
|
+
account,
|
|
335
|
+
secret,
|
|
336
|
+
digits,
|
|
337
|
+
period
|
|
338
|
+
});
|
|
339
|
+
}
|
|
363
340
|
};
|
|
364
341
|
};
|
|
365
342
|
|
|
366
|
-
// lib/two-factor.ts
|
|
343
|
+
// lib/auth/two-factor.ts
|
|
367
344
|
var CHALLENGED_PATHS = ["/callback/:id", "/one-tap/callback"];
|
|
368
345
|
var CODE_REQUIRED_PATHS = ["/two-factor/disable", "/two-factor/generate-backup-codes"];
|
|
369
346
|
function twoFactorPlugins(baseURL, { issuer, passwordless = false, challengeAfterOAuth = false }) {
|
|
@@ -420,9 +397,19 @@ function twoFactorPlugins(baseURL, { issuer, passwordless = false, challengeAfte
|
|
|
420
397
|
return [plugin, extras];
|
|
421
398
|
}
|
|
422
399
|
|
|
423
|
-
// lib/cookie-names.ts
|
|
400
|
+
// lib/security/cookie-names.ts
|
|
424
401
|
var LOGIN_REFERRER_COOKIE = "login_referrer";
|
|
425
402
|
var DEVICE_FINGERPRINT_HEADER = "x-device-fingerprint";
|
|
403
|
+
|
|
404
|
+
// lib/auth/base-url.ts
|
|
405
|
+
function getBaseUrl() {
|
|
406
|
+
const url = process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
|
|
407
|
+
return url.replace(/\/+$/, "");
|
|
408
|
+
}
|
|
409
|
+
function otherActiveAdminExists(excludeIds) {
|
|
410
|
+
const ids = sql.join(excludeIds.map((id) => sql`${id}`), sql`, `);
|
|
411
|
+
return sql`(select count(*) from (select ${users.id} as id from ${users} where ${users.role} = 'admin' and ${users.banned} = false for update) a where a.id not in (${ids})) > 0`;
|
|
412
|
+
}
|
|
426
413
|
async function isDeviceThrottled(fingerprint, max) {
|
|
427
414
|
try {
|
|
428
415
|
const [row] = await db.select({ count: authThrottle.count, windowStart: authThrottle.windowStart }).from(authThrottle).where(eq(authThrottle.fingerprint, fingerprint)).limit(1);
|
|
@@ -446,8 +433,10 @@ async function recordDeviceAttempt(fingerprint, meta) {
|
|
|
446
433
|
await db.insert(authThrottle).values(__spreadValues({ fingerprint, count: 1, windowStart: now }, seen)).onConflictDoUpdate({
|
|
447
434
|
target: authThrottle.fingerprint,
|
|
448
435
|
set: __spreadValues({
|
|
449
|
-
|
|
450
|
-
|
|
436
|
+
// ISO strings, not Dates: pg sends a raw Date as server-local time, which a
|
|
437
|
+
// tz-less `timestamp` column (stored as UTC) misreads on any non-UTC host.
|
|
438
|
+
count: sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then 1 else ${authThrottle.count} + 1 end`,
|
|
439
|
+
windowStart: sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then ${now.toISOString()} else ${authThrottle.windowStart} end`
|
|
451
440
|
}, seen)
|
|
452
441
|
});
|
|
453
442
|
} catch (error) {
|
|
@@ -466,15 +455,23 @@ async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
|
466
455
|
console.error("auth-throttle prune failed", error);
|
|
467
456
|
}
|
|
468
457
|
}
|
|
469
|
-
async function clearDeviceThrottle(fingerprint) {
|
|
470
|
-
try {
|
|
471
|
-
await db.delete(authThrottle).where(eq(authThrottle.fingerprint, fingerprint));
|
|
472
|
-
} catch (error) {
|
|
473
|
-
console.error("auth-throttle clear failed", error);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
458
|
|
|
477
459
|
// server/auth.ts
|
|
460
|
+
function checkDepsOnce() {
|
|
461
|
+
const flag = globalThis;
|
|
462
|
+
if (process.env.NODE_ENV !== "development" || flag.__xkDepsChecked) return;
|
|
463
|
+
flag.__xkDepsChecked = true;
|
|
464
|
+
const script = join(
|
|
465
|
+
/*turbopackIgnore: true*/
|
|
466
|
+
process.cwd(),
|
|
467
|
+
"node_modules/@xk2800/nextjs-template/scripts/check-deps.mjs"
|
|
468
|
+
);
|
|
469
|
+
if (!existsSync(script)) return;
|
|
470
|
+
execFile(process.execPath, [script], (_err, stdout) => {
|
|
471
|
+
if (stdout == null ? void 0 : stdout.trim()) console.log(stdout);
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
checkDepsOnce();
|
|
478
475
|
async function logFailedLogin(ctx, log) {
|
|
479
476
|
var _a, _b, _c;
|
|
480
477
|
try {
|
|
@@ -509,7 +506,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
509
506
|
userAgent: (_b = (_a = ctx.headers) == null ? void 0 : _a.get("user-agent")) != null ? _b : null
|
|
510
507
|
});
|
|
511
508
|
if (!config.RESEND_API_KEY) return;
|
|
512
|
-
const { EmailTemplatePasskeyChange } = await import('./
|
|
509
|
+
const { EmailTemplatePasskeyChange } = await import('./passkey-changed-KEGNTIPE.mjs');
|
|
513
510
|
await (await getResend()).emails.send({
|
|
514
511
|
from: EMAIL_FROM,
|
|
515
512
|
to: [user.email],
|
|
@@ -521,7 +518,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
521
518
|
location: formatLocation(lookupGeoLocation(ip)),
|
|
522
519
|
ipAddress: ip || "Unknown",
|
|
523
520
|
when: (/* @__PURE__ */ new Date()).toUTCString(),
|
|
524
|
-
manageUrl: `${
|
|
521
|
+
manageUrl: `${getBaseUrl()}/dashboard/settings`
|
|
525
522
|
})
|
|
526
523
|
});
|
|
527
524
|
} catch (error) {
|
|
@@ -572,6 +569,15 @@ async function packageSessionCreated(log, ...[session, context]) {
|
|
|
572
569
|
console.error("Failed to log login activity", error);
|
|
573
570
|
}
|
|
574
571
|
}
|
|
572
|
+
async function promoteFirstAdmin(user) {
|
|
573
|
+
var _a;
|
|
574
|
+
const adminEmail = (_a = process.env.ADMIN_EMAIL) == null ? void 0 : _a.trim().toLowerCase();
|
|
575
|
+
if (!adminEmail || !user.emailVerified || user.email.toLowerCase() !== adminEmail) return;
|
|
576
|
+
const [existing] = await db.select({ id: users.id }).from(users).where(eq(users.role, "admin")).limit(1);
|
|
577
|
+
if (existing) return;
|
|
578
|
+
await db.update(users).set({ role: "admin" }).where(eq(users.id, user.id));
|
|
579
|
+
user.role = "admin";
|
|
580
|
+
}
|
|
575
581
|
function createAuth(overrides = {}) {
|
|
576
582
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
577
583
|
const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
|
|
@@ -587,7 +593,7 @@ function createAuth(overrides = {}) {
|
|
|
587
593
|
"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: {...} })."
|
|
588
594
|
);
|
|
589
595
|
}
|
|
590
|
-
const baseURL =
|
|
596
|
+
const baseURL = getBaseUrl();
|
|
591
597
|
const log = (_a = overrides.logActivity) != null ? _a : logActivity;
|
|
592
598
|
const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
|
|
593
599
|
issuer: config.APP_NAME,
|
|
@@ -635,7 +641,7 @@ function createAuth(overrides = {}) {
|
|
|
635
641
|
// callbackURL) — see app/(auth)/forgot-password and reset-password for
|
|
636
642
|
// the pages this points at.
|
|
637
643
|
async sendResetPassword({ user, url }) {
|
|
638
|
-
const { EmailTemplateResetPassword } = await import('./
|
|
644
|
+
const { EmailTemplateResetPassword } = await import('./reset-password-64VQEXBW.mjs');
|
|
639
645
|
await (await getResend()).emails.send({
|
|
640
646
|
from: EMAIL_FROM,
|
|
641
647
|
to: [user.email],
|
|
@@ -651,8 +657,11 @@ function createAuth(overrides = {}) {
|
|
|
651
657
|
// callback that flips users.emailVerified on click.
|
|
652
658
|
emailVerification: {
|
|
653
659
|
autoSignInAfterVerification: true,
|
|
660
|
+
async afterEmailVerification(user) {
|
|
661
|
+
await promoteFirstAdmin(user);
|
|
662
|
+
},
|
|
654
663
|
async sendVerificationEmail({ user, url }) {
|
|
655
|
-
const { EmailTemplateVerifyEmail } = await import('./
|
|
664
|
+
const { EmailTemplateVerifyEmail } = await import('./verify-email-4KMNGDKN.mjs');
|
|
656
665
|
await (await getResend()).emails.send({
|
|
657
666
|
from: EMAIL_FROM,
|
|
658
667
|
to: [user.email],
|
|
@@ -694,6 +703,7 @@ function createAuth(overrides = {}) {
|
|
|
694
703
|
create: {
|
|
695
704
|
async after(user, context) {
|
|
696
705
|
var _a2, _b2, _c2, _d2;
|
|
706
|
+
await promoteFirstAdmin(user);
|
|
697
707
|
await ((_d2 = (_c2 = (_b2 = (_a2 = overrides.databaseHooks) == null ? void 0 : _a2.user) == null ? void 0 : _b2.create) == null ? void 0 : _c2.after) == null ? void 0 : _d2.call(_c2, user, context));
|
|
698
708
|
}
|
|
699
709
|
}
|
|
@@ -717,7 +727,7 @@ function createAuth(overrides = {}) {
|
|
|
717
727
|
// available together.
|
|
718
728
|
hooks: {
|
|
719
729
|
before: createAuthMiddleware(async (ctx) => {
|
|
720
|
-
var _a2, _b2, _c2, _d2;
|
|
730
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
721
731
|
if (ctx.path === "/sign-in/email" || ctx.path === "/sign-up/email") {
|
|
722
732
|
const fingerprint = (_a2 = ctx.headers) == null ? void 0 : _a2.get(DEVICE_FINGERPRINT_HEADER);
|
|
723
733
|
const ip = getClientIp(ctx.headers);
|
|
@@ -751,6 +761,9 @@ function createAuth(overrides = {}) {
|
|
|
751
761
|
}
|
|
752
762
|
return;
|
|
753
763
|
}
|
|
764
|
+
if (ctx.request && ((_c2 = ctx.path) == null ? void 0 : _c2.startsWith("/admin/")) && ctx.path !== "/admin/impersonate-user" && ctx.path !== "/admin/stop-impersonating") {
|
|
765
|
+
throw new APIError("FORBIDDEN", { message: "Use the dashboard to manage users." });
|
|
766
|
+
}
|
|
754
767
|
if (ctx.path === "/admin/impersonate-user" && overrides.impersonation === false) {
|
|
755
768
|
throw new APIError("FORBIDDEN", { message: "Impersonation is turned off." });
|
|
756
769
|
}
|
|
@@ -761,8 +774,8 @@ function createAuth(overrides = {}) {
|
|
|
761
774
|
throw new APIError("FORBIDDEN", { message: "Stop impersonating before deleting an account." });
|
|
762
775
|
}
|
|
763
776
|
if (current2.user.role === "admin") {
|
|
764
|
-
const [
|
|
765
|
-
if (
|
|
777
|
+
const [other] = await db.select({ n: sql`1` }).from(users).where(otherActiveAdminExists([current2.user.id])).limit(1);
|
|
778
|
+
if (!other) {
|
|
766
779
|
throw new APIError("FORBIDDEN", { message: "You're the only admin. Promote another user to admin first." });
|
|
767
780
|
}
|
|
768
781
|
}
|
|
@@ -775,7 +788,7 @@ function createAuth(overrides = {}) {
|
|
|
775
788
|
await log({
|
|
776
789
|
userId: current.session.impersonatedBy,
|
|
777
790
|
action: "impersonation_stopped",
|
|
778
|
-
description: `Admin stopped impersonating ${(
|
|
791
|
+
description: `Admin stopped impersonating ${(_e2 = (_d2 = target[0]) == null ? void 0 : _d2.email) != null ? _e2 : current.session.userId}`,
|
|
779
792
|
metadata: { impersonatedUserId: current.session.userId }
|
|
780
793
|
});
|
|
781
794
|
}
|
|
@@ -811,8 +824,6 @@ function createAuth(overrides = {}) {
|
|
|
811
824
|
if (failed) {
|
|
812
825
|
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
813
826
|
await logFailedLogin(ctx, log);
|
|
814
|
-
} else {
|
|
815
|
-
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
816
827
|
}
|
|
817
828
|
})
|
|
818
829
|
},
|
|
@@ -894,6 +905,6 @@ var auth = new Proxy({}, {
|
|
|
894
905
|
}
|
|
895
906
|
});
|
|
896
907
|
|
|
897
|
-
export { auth, createAuth };
|
|
898
|
-
//# sourceMappingURL=chunk-
|
|
899
|
-
//# sourceMappingURL=chunk-
|
|
908
|
+
export { auth, createAuth, getBaseUrl };
|
|
909
|
+
//# sourceMappingURL=chunk-ZQTI4T2K.mjs.map
|
|
910
|
+
//# sourceMappingURL=chunk-ZQTI4T2K.mjs.map
|