@xk2800/nextjs-template 0.7.2-beta.0 → 0.7.2-beta.10
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 -16
- 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 -23
- 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 -18
- 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 +284 -249
- 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 +302 -267
- 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 +63 -21
- package/dist/auth/helpers.d.ts +63 -21
- package/dist/auth/helpers.js +314 -268
- 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 +278 -245
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +8 -8
- package/dist/auth-client/index.d.mts +1214 -2526
- package/dist/auth-client/index.d.ts +1214 -2526
- 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-KA2KMGPY.mjs → chunk-3BH6BVBQ.mjs} +17 -8
- 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-YH53UPUW.mjs → chunk-EXMUANQ3.mjs} +4 -4
- package/dist/chunk-EXMUANQ3.mjs.map +1 -0
- package/dist/{chunk-VHNGYAIG.mjs → chunk-IH6CMZIN.mjs} +213 -220
- package/dist/chunk-IH6CMZIN.mjs.map +1 -0
- package/dist/chunk-LADVCLEQ.mjs +43 -0
- package/dist/chunk-LADVCLEQ.mjs.map +1 -0
- package/dist/{chunk-A6JXMHOQ.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-JUSU6UZA.mjs → chunk-S23GC776.mjs} +41 -29
- package/dist/chunk-S23GC776.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-4F6KE47S.mjs → chunk-ZOQHHFYA.mjs} +7 -4
- package/dist/chunk-ZOQHHFYA.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 -13
- 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 -5
- 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 -14
- 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 -13
- 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 -14
- 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 -24
- 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/{maintenance.ts → config/maintenance.ts} +0 -1
- 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-4C7JHGT5.mjs +0 -30
- package/dist/chunk-4C7JHGT5.mjs.map +0 -1
- package/dist/chunk-4F6KE47S.mjs.map +0 -1
- package/dist/chunk-6OAHCEDJ.mjs.map +0 -1
- package/dist/chunk-A6JXMHOQ.mjs.map +0 -1
- package/dist/chunk-HUEDEAY3.mjs.map +0 -1
- package/dist/chunk-JUSU6UZA.mjs.map +0 -1
- package/dist/chunk-KA2KMGPY.mjs.map +0 -1
- package/dist/chunk-L242CZ64.mjs.map +0 -1
- package/dist/chunk-NQELV53D.mjs.map +0 -1
- package/dist/chunk-VHNGYAIG.mjs.map +0 -1
- package/dist/chunk-YH53UPUW.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/{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
package/dist/auth/index.js
CHANGED
|
@@ -44,17 +44,22 @@ var __spreadValues = (a, b) => {
|
|
|
44
44
|
return a;
|
|
45
45
|
};
|
|
46
46
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
47
|
-
var __esm = (fn, res) => function __init() {
|
|
48
|
-
|
|
47
|
+
var __esm = (fn, res, err) => function __init() {
|
|
48
|
+
if (err) throw err[0];
|
|
49
|
+
try {
|
|
50
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
throw err = [e], e;
|
|
53
|
+
}
|
|
49
54
|
};
|
|
50
55
|
var __export = (target, all) => {
|
|
51
56
|
for (var name in all)
|
|
52
57
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
53
58
|
};
|
|
54
59
|
|
|
55
|
-
// components/email/
|
|
56
|
-
var
|
|
57
|
-
__export(
|
|
60
|
+
// components/email/security/passkey-changed.tsx
|
|
61
|
+
var passkey_changed_exports = {};
|
|
62
|
+
__export(passkey_changed_exports, {
|
|
58
63
|
EmailTemplatePasskeyChange: () => EmailTemplatePasskeyChange
|
|
59
64
|
});
|
|
60
65
|
function EmailTemplatePasskeyChange({
|
|
@@ -115,14 +120,14 @@ function EmailTemplatePasskeyChange({
|
|
|
115
120
|
] }) }) }) })
|
|
116
121
|
] });
|
|
117
122
|
}
|
|
118
|
-
var
|
|
119
|
-
"components/email/
|
|
123
|
+
var init_passkey_changed = __esm({
|
|
124
|
+
"components/email/security/passkey-changed.tsx"() {
|
|
120
125
|
}
|
|
121
126
|
});
|
|
122
127
|
|
|
123
|
-
// components/email/
|
|
124
|
-
var
|
|
125
|
-
__export(
|
|
128
|
+
// components/email/auth/reset-password.tsx
|
|
129
|
+
var reset_password_exports = {};
|
|
130
|
+
__export(reset_password_exports, {
|
|
126
131
|
EmailTemplateResetPassword: () => EmailTemplateResetPassword
|
|
127
132
|
});
|
|
128
133
|
function EmailTemplateResetPassword({ firstName, url }) {
|
|
@@ -159,14 +164,14 @@ function EmailTemplateResetPassword({ firstName, url }) {
|
|
|
159
164
|
] }) }) })
|
|
160
165
|
] });
|
|
161
166
|
}
|
|
162
|
-
var
|
|
163
|
-
"components/email/
|
|
167
|
+
var init_reset_password = __esm({
|
|
168
|
+
"components/email/auth/reset-password.tsx"() {
|
|
164
169
|
}
|
|
165
170
|
});
|
|
166
171
|
|
|
167
|
-
// components/email/
|
|
168
|
-
var
|
|
169
|
-
__export(
|
|
172
|
+
// components/email/auth/verify-email.tsx
|
|
173
|
+
var verify_email_exports = {};
|
|
174
|
+
__export(verify_email_exports, {
|
|
170
175
|
EmailTemplateVerifyEmail: () => EmailTemplateVerifyEmail
|
|
171
176
|
});
|
|
172
177
|
function EmailTemplateVerifyEmail({ firstName, url }) {
|
|
@@ -195,8 +200,8 @@ function EmailTemplateVerifyEmail({ firstName, url }) {
|
|
|
195
200
|
] }) }) }) })
|
|
196
201
|
] });
|
|
197
202
|
}
|
|
198
|
-
var
|
|
199
|
-
"components/email/
|
|
203
|
+
var init_verify_email = __esm({
|
|
204
|
+
"components/email/auth/verify-email.tsx"() {
|
|
200
205
|
}
|
|
201
206
|
});
|
|
202
207
|
|
|
@@ -220,12 +225,11 @@ __export(schema_exports, {
|
|
|
220
225
|
verifications: () => verifications
|
|
221
226
|
});
|
|
222
227
|
|
|
223
|
-
// lib/maintenance.ts
|
|
228
|
+
// lib/config/maintenance.ts
|
|
224
229
|
var DEFAULT_MAINTENANCE_EXEMPT_PATHS = [
|
|
225
230
|
"/",
|
|
226
231
|
"/features",
|
|
227
232
|
"/changelog",
|
|
228
|
-
"/changelog-template",
|
|
229
233
|
"/privacy",
|
|
230
234
|
"/terms"
|
|
231
235
|
];
|
|
@@ -288,7 +292,10 @@ var sessions = pgCore.pgTable("session", {
|
|
|
288
292
|
// Set by better-auth's admin plugin while this session is an admin
|
|
289
293
|
// impersonating another user; holds the impersonating admin's user id.
|
|
290
294
|
impersonatedBy: pgCore.text("impersonatedBy")
|
|
291
|
-
})
|
|
295
|
+
}, (table) => [
|
|
296
|
+
// Read by userId on every login (session count), ban/delete and the admin sessions view.
|
|
297
|
+
pgCore.index("session_user_idx").on(table.userId)
|
|
298
|
+
]);
|
|
292
299
|
var accounts = pgCore.pgTable("account", {
|
|
293
300
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
294
301
|
accountId: pgCore.text("accountId").notNull(),
|
|
@@ -337,7 +344,10 @@ var verifications = pgCore.pgTable("verification", {
|
|
|
337
344
|
});
|
|
338
345
|
var activityLogs = pgCore.pgTable("activity_log", {
|
|
339
346
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
340
|
-
|
|
347
|
+
// SET NULL, not cascade: deleting an admin must not erase the audit trail of
|
|
348
|
+
// what they did. actorEmail keeps who it was once the user row is gone.
|
|
349
|
+
userId: pgCore.text("userId").references(() => users.id, { onDelete: "set null" }),
|
|
350
|
+
actorEmail: pgCore.text("actorEmail"),
|
|
341
351
|
action: ActivityActionEnum("action").notNull(),
|
|
342
352
|
description: pgCore.text("description").notNull(),
|
|
343
353
|
ipAddress: pgCore.text("ipAddress"),
|
|
@@ -353,7 +363,11 @@ var activityLogs = pgCore.pgTable("activity_log", {
|
|
|
353
363
|
country: pgCore.text("country"),
|
|
354
364
|
city: pgCore.text("city"),
|
|
355
365
|
createdAt: pgCore.timestamp("createdAt").notNull().defaultNow()
|
|
356
|
-
})
|
|
366
|
+
}, (table) => [
|
|
367
|
+
// Per-user history, and the admin log's newest-first ordering.
|
|
368
|
+
pgCore.index("activity_log_user_created_idx").on(table.userId, table.createdAt),
|
|
369
|
+
pgCore.index("activity_log_created_idx").on(table.createdAt)
|
|
370
|
+
]);
|
|
357
371
|
var deviceFingerprints = pgCore.pgTable("device_fingerprint", {
|
|
358
372
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
359
373
|
userId: pgCore.text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
@@ -468,7 +482,9 @@ var envSchema = zod.z.object({
|
|
|
468
482
|
RESEND_MARKETING_SEGMENT_ID: zod.z.string().default(""),
|
|
469
483
|
// Sender for every transactional email. Must be on a domain verified in
|
|
470
484
|
// your Resend account.
|
|
471
|
-
|
|
485
|
+
// Resend's shared sandbox sender: works without a verified domain but only
|
|
486
|
+
// delivers to your own Resend account email. Set your verified domain for real use.
|
|
487
|
+
EMAIL_FROM: zod.z.string().default("Acme <onboarding@resend.dev>"),
|
|
472
488
|
// Display name for this deployment — shown as the authenticator-app label
|
|
473
489
|
// (2FA issuer) and the passkey relying-party name. Consuming projects set
|
|
474
490
|
// this in their own .env; defaults to the template name.
|
|
@@ -478,6 +494,9 @@ var envSchema = zod.z.object({
|
|
|
478
494
|
// a comma-separated list and sends through Resend (needs RESEND_API_KEY).
|
|
479
495
|
FEEDBACK_DISCORD_WEBHOOK_URL: zod.z.string().default(""),
|
|
480
496
|
FEEDBACK_EMAIL: zod.z.string().default(""),
|
|
497
|
+
// Seconds between feedback messages per user (default 30, 0 = off). Read
|
|
498
|
+
// straight from process.env in lib/feedback/route.ts; listed here for docs.
|
|
499
|
+
FEEDBACK_COOLDOWN_SECONDS: zod.z.string().default("30"),
|
|
481
500
|
// Web Push (example, see lib/push.ts). Generate keys with
|
|
482
501
|
// `bunx web-push generate-vapid-keys`. Blank = the notifications card is hidden.
|
|
483
502
|
// The public key is also read in the browser as NEXT_PUBLIC_VAPID_PUBLIC_KEY.
|
|
@@ -494,7 +513,12 @@ var envSchema = zod.z.object({
|
|
|
494
513
|
DB_DRIVER: zod.z.enum(["pg", "neon"]).default("pg"),
|
|
495
514
|
// Only relevant when DB_DRIVER=pg — whether the target Postgres server has SSL
|
|
496
515
|
// enabled. Self-hosted Postgres (e.g. via Docker/Dokploy) typically does not.
|
|
497
|
-
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true")
|
|
516
|
+
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true"),
|
|
517
|
+
// With DATABASE_SSL=true the server certificate is verified. Set the CA (PEM,
|
|
518
|
+
// "\n" for newlines) for a self-signed or private CA; DATABASE_SSL_INSECURE=true
|
|
519
|
+
// skips verification (encrypts only). Both are read in config/pg-ssl.ts.
|
|
520
|
+
DATABASE_SSL_CA: zod.z.string().default(""),
|
|
521
|
+
DATABASE_SSL_INSECURE: zod.z.string().default("false")
|
|
498
522
|
});
|
|
499
523
|
|
|
500
524
|
// config/env.ts
|
|
@@ -508,24 +532,47 @@ if (!results.success) {
|
|
|
508
532
|
}
|
|
509
533
|
var config = results.data;
|
|
510
534
|
|
|
535
|
+
// config/pg-ssl.ts
|
|
536
|
+
function pgSslOptions() {
|
|
537
|
+
var _a;
|
|
538
|
+
if (process.env.DATABASE_SSL_INSECURE === "true") return { rejectUnauthorized: false };
|
|
539
|
+
const ca = (_a = process.env.DATABASE_SSL_CA) == null ? void 0 : _a.replace(/\\n/g, "\n");
|
|
540
|
+
return __spreadValues({ rejectUnauthorized: true }, ca ? { ca } : {});
|
|
541
|
+
}
|
|
542
|
+
|
|
511
543
|
// server/db/index.ts
|
|
512
544
|
var db;
|
|
513
545
|
if (config.DB_DRIVER === "pg") {
|
|
514
546
|
const pool = new pg.Pool({
|
|
515
547
|
connectionString: config.DATABASE_URL,
|
|
516
|
-
ssl: config.DATABASE_SSL ?
|
|
548
|
+
ssl: config.DATABASE_SSL ? pgSslOptions() : void 0,
|
|
549
|
+
// pg waits forever by default; a hung DB would otherwise freeze every request (proxy reads settings).
|
|
550
|
+
connectionTimeoutMillis: 5e3,
|
|
551
|
+
query_timeout: 15e3
|
|
552
|
+
// roomy enough for the 10k-row exports
|
|
517
553
|
});
|
|
518
554
|
db = nodePostgres.drizzle(pool, {
|
|
519
555
|
schema: schema_exports,
|
|
520
|
-
logger:
|
|
556
|
+
logger: process.env.NODE_ENV === "development"
|
|
521
557
|
});
|
|
522
558
|
console.log("\u{1F7E1} Using PostgreSQL (pg) driver");
|
|
523
|
-
} else if (config.DB_DRIVER === "neon") {
|
|
524
|
-
const sql4 = serverless.neon(config.DATABASE_URL);
|
|
525
|
-
db = neonHttp.drizzle(sql4, { schema: schema_exports, logger: true });
|
|
526
|
-
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
527
559
|
} else {
|
|
528
|
-
|
|
560
|
+
serverless.neonConfig.fetchFunction = (url, init) => fetch(url, __spreadProps(__spreadValues({}, init), { signal: AbortSignal.timeout(15e3) }));
|
|
561
|
+
const sql6 = serverless.neon(config.DATABASE_URL);
|
|
562
|
+
db = neonHttp.drizzle(sql6, { schema: schema_exports, logger: process.env.NODE_ENV === "development" });
|
|
563
|
+
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// node_modules/@better-auth/utils/dist/bytes.mjs
|
|
567
|
+
function toBufferSource(data) {
|
|
568
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
569
|
+
if (!ArrayBuffer.isView(data)) return data;
|
|
570
|
+
if (data.buffer instanceof ArrayBuffer) return data;
|
|
571
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
|
|
572
|
+
}
|
|
573
|
+
function toUint8Array(data) {
|
|
574
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
575
|
+
return new Uint8Array(data);
|
|
529
576
|
}
|
|
530
577
|
|
|
531
578
|
// node_modules/@better-auth/utils/dist/base32.mjs
|
|
@@ -534,9 +581,7 @@ function getAlphabet(hex2) {
|
|
|
534
581
|
}
|
|
535
582
|
function createDecodeMap(alphabet) {
|
|
536
583
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
537
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
538
|
-
decodeMap.set(alphabet[i], i);
|
|
539
|
-
}
|
|
584
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
540
585
|
return decodeMap;
|
|
541
586
|
}
|
|
542
587
|
function base32Encode(data, alphabet, padding) {
|
|
@@ -551,9 +596,7 @@ function base32Encode(data, alphabet, padding) {
|
|
|
551
596
|
result += alphabet[buffer >> shift & 31];
|
|
552
597
|
}
|
|
553
598
|
}
|
|
554
|
-
if (shift > 0)
|
|
555
|
-
result += alphabet[buffer << 5 - shift & 31];
|
|
556
|
-
}
|
|
599
|
+
if (shift > 0) result += alphabet[buffer << 5 - shift & 31];
|
|
557
600
|
if (padding) {
|
|
558
601
|
const padCount = (8 - result.length % 8) % 8;
|
|
559
602
|
result += "=".repeat(padCount);
|
|
@@ -566,12 +609,9 @@ function base32Decode(data, alphabet) {
|
|
|
566
609
|
let buffer = 0;
|
|
567
610
|
let bitsCollected = 0;
|
|
568
611
|
for (const char of data) {
|
|
569
|
-
if (char === "=")
|
|
570
|
-
break;
|
|
612
|
+
if (char === "=") break;
|
|
571
613
|
const value = decodeMap.get(char);
|
|
572
|
-
if (value === void 0) {
|
|
573
|
-
throw new Error(`Invalid Base32 character: ${char}`);
|
|
574
|
-
}
|
|
614
|
+
if (value === void 0) throw new Error(`Invalid Base32 character: ${char}`);
|
|
575
615
|
buffer = buffer << 5 | value;
|
|
576
616
|
bitsCollected += 5;
|
|
577
617
|
while (bitsCollected >= 8) {
|
|
@@ -583,68 +623,34 @@ function base32Decode(data, alphabet) {
|
|
|
583
623
|
}
|
|
584
624
|
var base32 = {
|
|
585
625
|
/**
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
626
|
+
* Encodes data into a Base32 string.
|
|
627
|
+
* @param data - The data to encode (ArrayBuffer, number-based TypedArray, or string).
|
|
628
|
+
* @param options - Encoding options.
|
|
629
|
+
* @returns The Base32 encoded string.
|
|
630
|
+
*/
|
|
591
631
|
encode(data, options = {}) {
|
|
592
632
|
var _a;
|
|
593
633
|
const alphabet = getAlphabet();
|
|
594
|
-
|
|
595
|
-
return base32Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
634
|
+
return base32Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
596
635
|
},
|
|
597
636
|
/**
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
637
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
638
|
+
* @param data - The Base32 encoded string or ArrayBuffer/TypedArray.
|
|
639
|
+
* @returns The decoded Uint8Array.
|
|
640
|
+
*/
|
|
602
641
|
decode(data) {
|
|
603
|
-
if (typeof data !== "string")
|
|
604
|
-
data = new TextDecoder().decode(data);
|
|
605
|
-
}
|
|
642
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
606
643
|
const alphabet = getAlphabet();
|
|
607
644
|
return base32Decode(data, alphabet);
|
|
608
645
|
}
|
|
609
646
|
};
|
|
610
647
|
|
|
611
|
-
// node_modules/@better-auth/utils/dist/
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
}
|
|
618
|
-
if (data.byteLength === 0) {
|
|
619
|
-
return "";
|
|
620
|
-
}
|
|
621
|
-
const buffer = new Uint8Array(data);
|
|
622
|
-
let result = "";
|
|
623
|
-
for (const byte of buffer) {
|
|
624
|
-
result += byte.toString(16).padStart(2, "0");
|
|
625
|
-
}
|
|
626
|
-
return result;
|
|
627
|
-
},
|
|
628
|
-
decode: (data) => {
|
|
629
|
-
if (!data) {
|
|
630
|
-
return "";
|
|
631
|
-
}
|
|
632
|
-
if (typeof data === "string") {
|
|
633
|
-
if (data.length % 2 !== 0) {
|
|
634
|
-
throw new Error("Invalid hexadecimal string");
|
|
635
|
-
}
|
|
636
|
-
if (!new RegExp(`^[${hexadecimal}]+$`).test(data)) {
|
|
637
|
-
throw new Error("Invalid hexadecimal string");
|
|
638
|
-
}
|
|
639
|
-
const result = new Uint8Array(data.length / 2);
|
|
640
|
-
for (let i = 0; i < data.length; i += 2) {
|
|
641
|
-
result[i / 2] = parseInt(data.slice(i, i + 2), 16);
|
|
642
|
-
}
|
|
643
|
-
return new TextDecoder().decode(result);
|
|
644
|
-
}
|
|
645
|
-
return new TextDecoder().decode(data);
|
|
646
|
-
}
|
|
647
|
-
};
|
|
648
|
+
// node_modules/@better-auth/utils/dist/index.mjs
|
|
649
|
+
function getWebcryptoSubtle() {
|
|
650
|
+
const cr = typeof globalThis !== "undefined" && globalThis.crypto;
|
|
651
|
+
if (cr && typeof cr.subtle === "object" && cr.subtle != null) return cr.subtle;
|
|
652
|
+
throw new Error("crypto.subtle must be defined");
|
|
653
|
+
}
|
|
648
654
|
|
|
649
655
|
// node_modules/@better-auth/utils/dist/base64.mjs
|
|
650
656
|
function getAlphabet2(urlSafe) {
|
|
@@ -662,9 +668,7 @@ function base64Encode(data, alphabet, padding) {
|
|
|
662
668
|
result += alphabet[buffer >> shift & 63];
|
|
663
669
|
}
|
|
664
670
|
}
|
|
665
|
-
if (shift > 0)
|
|
666
|
-
result += alphabet[buffer << 6 - shift & 63];
|
|
667
|
-
}
|
|
671
|
+
if (shift > 0) result += alphabet[buffer << 6 - shift & 63];
|
|
668
672
|
if (padding) {
|
|
669
673
|
const padCount = (4 - result.length % 4) % 4;
|
|
670
674
|
result += "=".repeat(padCount);
|
|
@@ -673,19 +677,14 @@ function base64Encode(data, alphabet, padding) {
|
|
|
673
677
|
}
|
|
674
678
|
function base64Decode(data, alphabet) {
|
|
675
679
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
676
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
677
|
-
decodeMap.set(alphabet[i], i);
|
|
678
|
-
}
|
|
680
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
679
681
|
const result = [];
|
|
680
682
|
let buffer = 0;
|
|
681
683
|
let bitsCollected = 0;
|
|
682
684
|
for (const char of data) {
|
|
683
|
-
if (char === "=")
|
|
684
|
-
break;
|
|
685
|
+
if (char === "=") break;
|
|
685
686
|
const value = decodeMap.get(char);
|
|
686
|
-
if (value === void 0) {
|
|
687
|
-
throw new Error(`Invalid Base64 character: ${char}`);
|
|
688
|
-
}
|
|
687
|
+
if (value === void 0) throw new Error(`Invalid Base64 character: ${char}`);
|
|
689
688
|
buffer = buffer << 6 | value;
|
|
690
689
|
bitsCollected += 6;
|
|
691
690
|
if (bitsCollected >= 8) {
|
|
@@ -699,15 +698,11 @@ var base64 = {
|
|
|
699
698
|
encode(data, options = {}) {
|
|
700
699
|
var _a;
|
|
701
700
|
const alphabet = getAlphabet2(false);
|
|
702
|
-
|
|
703
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
701
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
704
702
|
},
|
|
705
703
|
decode(data) {
|
|
706
|
-
if (typeof data !== "string")
|
|
707
|
-
|
|
708
|
-
}
|
|
709
|
-
const urlSafe = data.includes("-") || data.includes("_");
|
|
710
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
704
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
705
|
+
const alphabet = getAlphabet2(data.includes("-") || data.includes("_"));
|
|
711
706
|
return base64Decode(data, alphabet);
|
|
712
707
|
}
|
|
713
708
|
};
|
|
@@ -715,152 +710,142 @@ var base64Url = {
|
|
|
715
710
|
encode(data, options = {}) {
|
|
716
711
|
var _a;
|
|
717
712
|
const alphabet = getAlphabet2(true);
|
|
718
|
-
|
|
719
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
713
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
720
714
|
},
|
|
721
715
|
decode(data) {
|
|
722
|
-
|
|
723
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
724
|
-
return base64Decode(data, alphabet);
|
|
716
|
+
return base64Decode(data, getAlphabet2(data.includes("-") || data.includes("_")));
|
|
725
717
|
}
|
|
726
718
|
};
|
|
727
719
|
|
|
728
|
-
// node_modules/@
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
720
|
+
// node_modules/@noble/hashes/utils.js
|
|
721
|
+
var hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
722
|
+
// @ts-ignore
|
|
723
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
724
|
+
))();
|
|
725
|
+
function asciiToBase16(ch) {
|
|
726
|
+
return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
|
|
727
|
+
}
|
|
728
|
+
function hexToBytes(hex2) {
|
|
729
|
+
if (typeof hex2 !== "string")
|
|
730
|
+
throw new TypeError("hex string expected, got " + typeof hex2);
|
|
731
|
+
if (hasHexBuiltin) {
|
|
732
|
+
try {
|
|
733
|
+
return Uint8Array.fromHex(hex2);
|
|
734
|
+
} catch (error) {
|
|
735
|
+
if (error instanceof SyntaxError)
|
|
736
|
+
throw new RangeError(error.message);
|
|
737
|
+
throw error;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
const hl = hex2.length;
|
|
741
|
+
const al = hl / 2;
|
|
742
|
+
if (hl % 2)
|
|
743
|
+
throw new RangeError("hex string expected, got unpadded hex of length " + hl);
|
|
744
|
+
const array = new Uint8Array(al);
|
|
745
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
746
|
+
const n1 = asciiToBase16(hex2.charCodeAt(hi));
|
|
747
|
+
const n2 = asciiToBase16(hex2.charCodeAt(hi + 1));
|
|
748
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
749
|
+
const char = hex2[hi] + hex2[hi + 1];
|
|
750
|
+
throw new RangeError('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
751
|
+
}
|
|
752
|
+
array[ai] = n1 * 16 + n2;
|
|
753
|
+
}
|
|
754
|
+
return array;
|
|
734
755
|
}
|
|
735
756
|
|
|
757
|
+
// node_modules/@better-auth/utils/dist/hex.mjs
|
|
758
|
+
var toBytes = (data) => hexToBytes(data);
|
|
759
|
+
var hex = {
|
|
760
|
+
encode: (data) => {
|
|
761
|
+
const buffer = toUint8Array(data);
|
|
762
|
+
if (buffer.byteLength === 0) return "";
|
|
763
|
+
let result = "";
|
|
764
|
+
for (const byte of buffer) result += byte.toString(16).padStart(2, "0");
|
|
765
|
+
return result;
|
|
766
|
+
},
|
|
767
|
+
decode: (data) => {
|
|
768
|
+
if (!data) return "";
|
|
769
|
+
if (typeof data === "string") return new TextDecoder().decode(toBytes(data));
|
|
770
|
+
return new TextDecoder().decode(data);
|
|
771
|
+
},
|
|
772
|
+
toBytes
|
|
773
|
+
};
|
|
774
|
+
|
|
736
775
|
// node_modules/@better-auth/utils/dist/hmac.mjs
|
|
737
776
|
var createHMAC = (algorithm = "SHA-256", encoding = "none") => {
|
|
738
|
-
const
|
|
777
|
+
const hmac2 = {
|
|
739
778
|
importKey: async (key, keyUsage) => {
|
|
740
|
-
return getWebcryptoSubtle().importKey(
|
|
741
|
-
"
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
false,
|
|
745
|
-
[keyUsage]
|
|
746
|
-
);
|
|
779
|
+
return getWebcryptoSubtle().importKey("raw", toBufferSource(key), {
|
|
780
|
+
name: "HMAC",
|
|
781
|
+
hash: { name: algorithm }
|
|
782
|
+
}, false, [keyUsage]);
|
|
747
783
|
},
|
|
748
784
|
sign: async (hmacKey, data) => {
|
|
749
|
-
if (typeof hmacKey === "string")
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
hmacKey,
|
|
755
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
756
|
-
);
|
|
757
|
-
if (encoding === "hex") {
|
|
758
|
-
return hex.encode(signature);
|
|
759
|
-
}
|
|
760
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
761
|
-
return base64Url.encode(signature, {
|
|
762
|
-
padding: encoding !== "base64urlnopad"
|
|
763
|
-
});
|
|
764
|
-
}
|
|
785
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "sign");
|
|
786
|
+
const signature = await getWebcryptoSubtle().sign("HMAC", hmacKey, toBufferSource(data));
|
|
787
|
+
if (encoding === "hex") return hex.encode(signature);
|
|
788
|
+
if (encoding === "base64") return base64.encode(signature);
|
|
789
|
+
if (encoding === "base64url" || encoding === "base64urlnopad") return base64Url.encode(signature, { padding: encoding !== "base64urlnopad" });
|
|
765
790
|
return signature;
|
|
766
791
|
},
|
|
767
792
|
verify: async (hmacKey, data, signature) => {
|
|
768
|
-
if (typeof hmacKey === "string")
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
signature = hex.decode(signature);
|
|
773
|
-
}
|
|
774
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
775
|
-
signature = await base64.decode(signature);
|
|
776
|
-
}
|
|
777
|
-
return getWebcryptoSubtle().verify(
|
|
778
|
-
"HMAC",
|
|
779
|
-
hmacKey,
|
|
780
|
-
typeof signature === "string" ? new TextEncoder().encode(signature) : signature,
|
|
781
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
782
|
-
);
|
|
793
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "verify");
|
|
794
|
+
if (encoding === "hex") signature = typeof signature === "string" ? hex.toBytes(signature) : signature;
|
|
795
|
+
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") signature = await base64.decode(signature);
|
|
796
|
+
return getWebcryptoSubtle().verify("HMAC", hmacKey, toBufferSource(signature), toBufferSource(data));
|
|
783
797
|
}
|
|
784
798
|
};
|
|
785
|
-
return
|
|
799
|
+
return hmac2;
|
|
786
800
|
};
|
|
787
801
|
|
|
788
802
|
// node_modules/@better-auth/utils/dist/otp.mjs
|
|
789
803
|
var defaultPeriod = 30;
|
|
790
804
|
var defaultDigits = 6;
|
|
805
|
+
var hmac = createHMAC("SHA-1");
|
|
791
806
|
function constantTimeEqualOTP(input, expected) {
|
|
792
807
|
let difference = input.length ^ expected.length;
|
|
793
|
-
for (let i = 0; i < expected.length; i++)
|
|
794
|
-
difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
795
|
-
}
|
|
808
|
+
for (let i = 0; i < expected.length; i++) difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
796
809
|
return difference === 0;
|
|
797
810
|
}
|
|
798
|
-
async function generateHOTP(
|
|
799
|
-
counter,
|
|
800
|
-
digits,
|
|
801
|
-
hash = "SHA-1"
|
|
802
|
-
}) {
|
|
811
|
+
async function generateHOTP(key, { counter, digits }) {
|
|
803
812
|
const _digits = digits != null ? digits : defaultDigits;
|
|
804
|
-
if (_digits < 1 || _digits > 8)
|
|
805
|
-
|
|
806
|
-
}
|
|
807
|
-
const buffer = new ArrayBuffer(8);
|
|
813
|
+
if (_digits < 1 || _digits > 8) throw new TypeError("Digits must be between 1 and 8");
|
|
814
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
808
815
|
new DataView(buffer).setBigUint64(0, BigInt(counter), false);
|
|
809
816
|
const bytes = new Uint8Array(buffer);
|
|
810
|
-
const
|
|
817
|
+
const signature = await hmac.sign(key, bytes);
|
|
818
|
+
const hmacResult = new Uint8Array(signature);
|
|
811
819
|
const offset = hmacResult[hmacResult.length - 1] & 15;
|
|
812
|
-
|
|
813
|
-
const otp = truncated % 10 ** _digits;
|
|
814
|
-
return otp.toString().padStart(_digits, "0");
|
|
820
|
+
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");
|
|
815
821
|
}
|
|
816
|
-
async function generateTOTP(
|
|
822
|
+
async function generateTOTP(key, options) {
|
|
817
823
|
var _a, _b;
|
|
818
824
|
const digits = (_a = options == null ? void 0 : options.digits) != null ? _a : defaultDigits;
|
|
819
|
-
const
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
825
|
+
const milliseconds = ((_b = options == null ? void 0 : options.period) != null ? _b : defaultPeriod) * 1e3;
|
|
826
|
+
return await generateHOTP(key, {
|
|
827
|
+
counter: Math.floor(Date.now() / milliseconds),
|
|
828
|
+
digits
|
|
829
|
+
});
|
|
823
830
|
}
|
|
824
|
-
async function verifyTOTP(otp, {
|
|
825
|
-
window = 1,
|
|
826
|
-
digits = defaultDigits,
|
|
827
|
-
secret,
|
|
828
|
-
period = defaultPeriod
|
|
829
|
-
}) {
|
|
831
|
+
async function verifyTOTP(otp, { window = 1, digits = defaultDigits, key, period = defaultPeriod }) {
|
|
830
832
|
const milliseconds = period * 1e3;
|
|
831
833
|
const counter = Math.floor(Date.now() / milliseconds);
|
|
832
834
|
let matched = false;
|
|
833
|
-
for (let i = -window; i <= window; i++) {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
});
|
|
838
|
-
matched = constantTimeEqualOTP(otp, generatedOTP) || matched;
|
|
839
|
-
}
|
|
835
|
+
for (let i = -window; i <= window; i++) matched = constantTimeEqualOTP(otp, await generateHOTP(key, {
|
|
836
|
+
counter: counter + i,
|
|
837
|
+
digits
|
|
838
|
+
})) || matched;
|
|
840
839
|
return matched;
|
|
841
840
|
}
|
|
842
|
-
function generateQRCode({
|
|
843
|
-
issuer
|
|
844
|
-
account,
|
|
845
|
-
secret,
|
|
846
|
-
digits = defaultDigits,
|
|
847
|
-
period = defaultPeriod
|
|
848
|
-
}) {
|
|
849
|
-
const encodedIssuer = encodeURIComponent(issuer);
|
|
850
|
-
const encodedAccountName = encodeURIComponent(account);
|
|
851
|
-
const baseURI = `otpauth://totp/${encodedIssuer}:${encodedAccountName}`;
|
|
841
|
+
function generateQRCode({ issuer, account, secret, digits = defaultDigits, period = defaultPeriod }) {
|
|
842
|
+
const baseURI = `otpauth://totp/${encodeURIComponent(issuer)}:${encodeURIComponent(account)}`;
|
|
852
843
|
const params = new URLSearchParams({
|
|
853
|
-
secret: base32.encode(secret, {
|
|
854
|
-
padding: false
|
|
855
|
-
}),
|
|
844
|
+
secret: base32.encode(secret, { padding: false }),
|
|
856
845
|
issuer
|
|
857
846
|
});
|
|
858
|
-
if (digits !== void 0)
|
|
859
|
-
|
|
860
|
-
}
|
|
861
|
-
if (period !== void 0) {
|
|
862
|
-
params.set("period", period.toString());
|
|
863
|
-
}
|
|
847
|
+
if (digits !== void 0) params.set("digits", digits.toString());
|
|
848
|
+
if (period !== void 0) params.set("period", period.toString());
|
|
864
849
|
return `${baseURI}?${params.toString()}`;
|
|
865
850
|
}
|
|
866
851
|
var createOTP = (secret, opts) => {
|
|
@@ -868,14 +853,38 @@ var createOTP = (secret, opts) => {
|
|
|
868
853
|
const digits = (_a = void 0 ) != null ? _a : defaultDigits;
|
|
869
854
|
const period = (_b = void 0 ) != null ? _b : defaultPeriod;
|
|
870
855
|
return {
|
|
871
|
-
hotp: (counter) =>
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
856
|
+
hotp: async (counter) => {
|
|
857
|
+
return generateHOTP(await hmac.importKey(secret, "sign"), {
|
|
858
|
+
counter,
|
|
859
|
+
digits
|
|
860
|
+
});
|
|
861
|
+
},
|
|
862
|
+
totp: async () => {
|
|
863
|
+
return generateTOTP(await hmac.importKey(secret, "sign"), {
|
|
864
|
+
digits,
|
|
865
|
+
period
|
|
866
|
+
});
|
|
867
|
+
},
|
|
868
|
+
verify: async (otp, options) => {
|
|
869
|
+
return verifyTOTP(otp, __spreadValues({
|
|
870
|
+
key: await hmac.importKey(secret, "sign"),
|
|
871
|
+
digits,
|
|
872
|
+
period
|
|
873
|
+
}, options));
|
|
874
|
+
},
|
|
875
|
+
url: (issuer, account) => {
|
|
876
|
+
return generateQRCode({
|
|
877
|
+
issuer,
|
|
878
|
+
account,
|
|
879
|
+
secret,
|
|
880
|
+
digits,
|
|
881
|
+
period
|
|
882
|
+
});
|
|
883
|
+
}
|
|
875
884
|
};
|
|
876
885
|
};
|
|
877
886
|
|
|
878
|
-
// lib/two-factor.ts
|
|
887
|
+
// lib/auth/two-factor.ts
|
|
879
888
|
var CHALLENGED_PATHS = ["/callback/:id", "/one-tap/callback"];
|
|
880
889
|
var CODE_REQUIRED_PATHS = ["/two-factor/disable", "/two-factor/generate-backup-codes"];
|
|
881
890
|
function twoFactorPlugins(baseURL, { issuer, passwordless = false, challengeAfterOAuth = false }) {
|
|
@@ -948,6 +957,8 @@ async function logActivity({
|
|
|
948
957
|
try {
|
|
949
958
|
await db.insert(activityLogs).values({
|
|
950
959
|
userId,
|
|
960
|
+
// Snapshot the email at write time; survives deletion of the user row.
|
|
961
|
+
actorEmail: drizzleOrm.sql`(select "email" from "user" where "id" = ${userId})`,
|
|
951
962
|
action,
|
|
952
963
|
description,
|
|
953
964
|
ipAddress: ipAddress || null,
|
|
@@ -968,7 +979,7 @@ var countryNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
|
968
979
|
function getClientIp(headers) {
|
|
969
980
|
var _a;
|
|
970
981
|
const forwardedFor = headers == null ? void 0 : headers.get("x-forwarded-for");
|
|
971
|
-
if (forwardedFor) return forwardedFor.split(",")
|
|
982
|
+
if (forwardedFor) return forwardedFor.split(",").at(-1).trim();
|
|
972
983
|
return (_a = headers == null ? void 0 : headers.get("x-real-ip")) != null ? _a : null;
|
|
973
984
|
}
|
|
974
985
|
function parseUserAgent(userAgent) {
|
|
@@ -1007,11 +1018,21 @@ function formatLocation({ country, city }) {
|
|
|
1007
1018
|
return [city, country].filter(Boolean).join(", ");
|
|
1008
1019
|
}
|
|
1009
1020
|
|
|
1010
|
-
// lib/cookie-names.ts
|
|
1021
|
+
// lib/security/cookie-names.ts
|
|
1011
1022
|
var LOGIN_REFERRER_COOKIE = "login_referrer";
|
|
1012
1023
|
var DEVICE_FINGERPRINT_HEADER = "x-device-fingerprint";
|
|
1013
1024
|
|
|
1014
|
-
// lib/auth-
|
|
1025
|
+
// lib/auth/base-url.ts
|
|
1026
|
+
function getBaseUrl() {
|
|
1027
|
+
const url = process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
|
|
1028
|
+
return url.replace(/\/+$/, "");
|
|
1029
|
+
}
|
|
1030
|
+
function otherActiveAdminExists(excludeIds) {
|
|
1031
|
+
const ids = drizzleOrm.sql.join(excludeIds.map((id) => drizzleOrm.sql`${id}`), drizzleOrm.sql`, `);
|
|
1032
|
+
return drizzleOrm.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`;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// lib/auth/throttle-limits.ts
|
|
1015
1036
|
var WINDOW_MS = 15 * 60 * 1e3;
|
|
1016
1037
|
var MAX = 10;
|
|
1017
1038
|
var MAX_IP = MAX * 3;
|
|
@@ -1022,7 +1043,7 @@ function isOverLimit(row, now, max = MAX) {
|
|
|
1022
1043
|
return row.count >= max;
|
|
1023
1044
|
}
|
|
1024
1045
|
|
|
1025
|
-
// lib/auth
|
|
1046
|
+
// lib/auth/throttle.ts
|
|
1026
1047
|
async function isDeviceThrottled(fingerprint, max) {
|
|
1027
1048
|
try {
|
|
1028
1049
|
const [row] = await db.select({ count: authThrottle.count, windowStart: authThrottle.windowStart }).from(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint)).limit(1);
|
|
@@ -1046,8 +1067,10 @@ async function recordDeviceAttempt(fingerprint, meta) {
|
|
|
1046
1067
|
await db.insert(authThrottle).values(__spreadValues({ fingerprint, count: 1, windowStart: now }, seen)).onConflictDoUpdate({
|
|
1047
1068
|
target: authThrottle.fingerprint,
|
|
1048
1069
|
set: __spreadValues({
|
|
1049
|
-
|
|
1050
|
-
|
|
1070
|
+
// ISO strings, not Dates: pg sends a raw Date as server-local time, which a
|
|
1071
|
+
// tz-less `timestamp` column (stored as UTC) misreads on any non-UTC host.
|
|
1072
|
+
count: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then 1 else ${authThrottle.count} + 1 end`,
|
|
1073
|
+
windowStart: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then ${now.toISOString()} else ${authThrottle.windowStart} end`
|
|
1051
1074
|
}, seen)
|
|
1052
1075
|
});
|
|
1053
1076
|
} catch (error) {
|
|
@@ -1066,15 +1089,9 @@ async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
|
1066
1089
|
console.error("auth-throttle prune failed", error);
|
|
1067
1090
|
}
|
|
1068
1091
|
}
|
|
1069
|
-
async function clearDeviceThrottle(fingerprint) {
|
|
1070
|
-
try {
|
|
1071
|
-
await db.delete(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint));
|
|
1072
|
-
} catch (error) {
|
|
1073
|
-
console.error("auth-throttle clear failed", error);
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
1092
|
var SETTINGS_ROW_ID = "default";
|
|
1077
1093
|
var CACHE_TTL_MS = 1e4;
|
|
1094
|
+
var FAILURE_CACHE_TTL_MS = 5e3;
|
|
1078
1095
|
var cached = null;
|
|
1079
1096
|
function fallbackSettings() {
|
|
1080
1097
|
return {
|
|
@@ -1117,7 +1134,9 @@ async function getSystemSettings() {
|
|
|
1117
1134
|
return value;
|
|
1118
1135
|
} catch (error) {
|
|
1119
1136
|
console.error("Failed to load system settings, failing open:", error);
|
|
1120
|
-
|
|
1137
|
+
const value = fallbackSettings();
|
|
1138
|
+
cached = { value, expiresAt: now + FAILURE_CACHE_TTL_MS };
|
|
1139
|
+
return value;
|
|
1121
1140
|
}
|
|
1122
1141
|
}
|
|
1123
1142
|
async function getEffectiveAuthFlags() {
|
|
@@ -1174,7 +1193,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1174
1193
|
userAgent: (_b = (_a = ctx.headers) == null ? void 0 : _a.get("user-agent")) != null ? _b : null
|
|
1175
1194
|
});
|
|
1176
1195
|
if (!config.RESEND_API_KEY) return;
|
|
1177
|
-
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (
|
|
1196
|
+
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (init_passkey_changed(), passkey_changed_exports));
|
|
1178
1197
|
await (await getResend()).emails.send({
|
|
1179
1198
|
from: EMAIL_FROM,
|
|
1180
1199
|
to: [user.email],
|
|
@@ -1186,7 +1205,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1186
1205
|
location: formatLocation(lookupGeoLocation(ip)),
|
|
1187
1206
|
ipAddress: ip || "Unknown",
|
|
1188
1207
|
when: (/* @__PURE__ */ new Date()).toUTCString(),
|
|
1189
|
-
manageUrl: `${
|
|
1208
|
+
manageUrl: `${getBaseUrl()}/dashboard/settings`
|
|
1190
1209
|
})
|
|
1191
1210
|
});
|
|
1192
1211
|
} catch (error) {
|
|
@@ -1237,6 +1256,15 @@ async function packageSessionCreated(log, ...[session, context]) {
|
|
|
1237
1256
|
console.error("Failed to log login activity", error);
|
|
1238
1257
|
}
|
|
1239
1258
|
}
|
|
1259
|
+
async function promoteFirstAdmin(user) {
|
|
1260
|
+
var _a;
|
|
1261
|
+
const adminEmail = (_a = process.env.ADMIN_EMAIL) == null ? void 0 : _a.trim().toLowerCase();
|
|
1262
|
+
if (!adminEmail || !user.emailVerified || user.email.toLowerCase() !== adminEmail) return;
|
|
1263
|
+
const [existing] = await db.select({ id: users.id }).from(users).where(drizzleOrm.eq(users.role, "admin")).limit(1);
|
|
1264
|
+
if (existing) return;
|
|
1265
|
+
await db.update(users).set({ role: "admin" }).where(drizzleOrm.eq(users.id, user.id));
|
|
1266
|
+
user.role = "admin";
|
|
1267
|
+
}
|
|
1240
1268
|
function createAuth(overrides = {}) {
|
|
1241
1269
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1242
1270
|
const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
|
|
@@ -1252,7 +1280,7 @@ function createAuth(overrides = {}) {
|
|
|
1252
1280
|
"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: {...} })."
|
|
1253
1281
|
);
|
|
1254
1282
|
}
|
|
1255
|
-
const baseURL =
|
|
1283
|
+
const baseURL = getBaseUrl();
|
|
1256
1284
|
const log = (_a = overrides.logActivity) != null ? _a : logActivity;
|
|
1257
1285
|
const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
|
|
1258
1286
|
issuer: config.APP_NAME,
|
|
@@ -1300,7 +1328,7 @@ function createAuth(overrides = {}) {
|
|
|
1300
1328
|
// callbackURL) — see app/(auth)/forgot-password and reset-password for
|
|
1301
1329
|
// the pages this points at.
|
|
1302
1330
|
async sendResetPassword({ user, url }) {
|
|
1303
|
-
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (
|
|
1331
|
+
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (init_reset_password(), reset_password_exports));
|
|
1304
1332
|
await (await getResend()).emails.send({
|
|
1305
1333
|
from: EMAIL_FROM,
|
|
1306
1334
|
to: [user.email],
|
|
@@ -1316,8 +1344,11 @@ function createAuth(overrides = {}) {
|
|
|
1316
1344
|
// callback that flips users.emailVerified on click.
|
|
1317
1345
|
emailVerification: {
|
|
1318
1346
|
autoSignInAfterVerification: true,
|
|
1347
|
+
async afterEmailVerification(user) {
|
|
1348
|
+
await promoteFirstAdmin(user);
|
|
1349
|
+
},
|
|
1319
1350
|
async sendVerificationEmail({ user, url }) {
|
|
1320
|
-
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (
|
|
1351
|
+
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (init_verify_email(), verify_email_exports));
|
|
1321
1352
|
await (await getResend()).emails.send({
|
|
1322
1353
|
from: EMAIL_FROM,
|
|
1323
1354
|
to: [user.email],
|
|
@@ -1359,6 +1390,7 @@ function createAuth(overrides = {}) {
|
|
|
1359
1390
|
create: {
|
|
1360
1391
|
async after(user, context) {
|
|
1361
1392
|
var _a2, _b2, _c2, _d2;
|
|
1393
|
+
await promoteFirstAdmin(user);
|
|
1362
1394
|
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));
|
|
1363
1395
|
}
|
|
1364
1396
|
}
|
|
@@ -1382,7 +1414,7 @@ function createAuth(overrides = {}) {
|
|
|
1382
1414
|
// available together.
|
|
1383
1415
|
hooks: {
|
|
1384
1416
|
before: api.createAuthMiddleware(async (ctx) => {
|
|
1385
|
-
var _a2, _b2, _c2, _d2;
|
|
1417
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
1386
1418
|
if (ctx.path === "/sign-in/email" || ctx.path === "/sign-up/email") {
|
|
1387
1419
|
const fingerprint = (_a2 = ctx.headers) == null ? void 0 : _a2.get(DEVICE_FINGERPRINT_HEADER);
|
|
1388
1420
|
const ip = getClientIp(ctx.headers);
|
|
@@ -1416,6 +1448,9 @@ function createAuth(overrides = {}) {
|
|
|
1416
1448
|
}
|
|
1417
1449
|
return;
|
|
1418
1450
|
}
|
|
1451
|
+
if (ctx.request && ((_c2 = ctx.path) == null ? void 0 : _c2.startsWith("/admin/")) && ctx.path !== "/admin/impersonate-user" && ctx.path !== "/admin/stop-impersonating") {
|
|
1452
|
+
throw new api.APIError("FORBIDDEN", { message: "Use the dashboard to manage users." });
|
|
1453
|
+
}
|
|
1419
1454
|
if (ctx.path === "/admin/impersonate-user" && overrides.impersonation === false) {
|
|
1420
1455
|
throw new api.APIError("FORBIDDEN", { message: "Impersonation is turned off." });
|
|
1421
1456
|
}
|
|
@@ -1426,8 +1461,8 @@ function createAuth(overrides = {}) {
|
|
|
1426
1461
|
throw new api.APIError("FORBIDDEN", { message: "Stop impersonating before deleting an account." });
|
|
1427
1462
|
}
|
|
1428
1463
|
if (current2.user.role === "admin") {
|
|
1429
|
-
const [
|
|
1430
|
-
if (
|
|
1464
|
+
const [other] = await db.select({ n: drizzleOrm.sql`1` }).from(users).where(otherActiveAdminExists([current2.user.id])).limit(1);
|
|
1465
|
+
if (!other) {
|
|
1431
1466
|
throw new api.APIError("FORBIDDEN", { message: "You're the only admin. Promote another user to admin first." });
|
|
1432
1467
|
}
|
|
1433
1468
|
}
|
|
@@ -1440,7 +1475,7 @@ function createAuth(overrides = {}) {
|
|
|
1440
1475
|
await log({
|
|
1441
1476
|
userId: current.session.impersonatedBy,
|
|
1442
1477
|
action: "impersonation_stopped",
|
|
1443
|
-
description: `Admin stopped impersonating ${(
|
|
1478
|
+
description: `Admin stopped impersonating ${(_e2 = (_d2 = target[0]) == null ? void 0 : _d2.email) != null ? _e2 : current.session.userId}`,
|
|
1444
1479
|
metadata: { impersonatedUserId: current.session.userId }
|
|
1445
1480
|
});
|
|
1446
1481
|
}
|
|
@@ -1476,8 +1511,6 @@ function createAuth(overrides = {}) {
|
|
|
1476
1511
|
if (failed) {
|
|
1477
1512
|
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
1478
1513
|
await logFailedLogin(ctx, log);
|
|
1479
|
-
} else {
|
|
1480
|
-
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
1481
1514
|
}
|
|
1482
1515
|
})
|
|
1483
1516
|
},
|