@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/api/feedback.js
CHANGED
|
@@ -47,17 +47,22 @@ var __spreadValues = (a, b) => {
|
|
|
47
47
|
return a;
|
|
48
48
|
};
|
|
49
49
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
50
|
-
var __esm = (fn, res) => function __init() {
|
|
51
|
-
|
|
50
|
+
var __esm = (fn, res, err) => function __init() {
|
|
51
|
+
if (err) throw err[0];
|
|
52
|
+
try {
|
|
53
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
throw err = [e], e;
|
|
56
|
+
}
|
|
52
57
|
};
|
|
53
58
|
var __export = (target, all) => {
|
|
54
59
|
for (var name in all)
|
|
55
60
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
56
61
|
};
|
|
57
62
|
|
|
58
|
-
// components/email/
|
|
59
|
-
var
|
|
60
|
-
__export(
|
|
63
|
+
// components/email/security/passkey-changed.tsx
|
|
64
|
+
var passkey_changed_exports = {};
|
|
65
|
+
__export(passkey_changed_exports, {
|
|
61
66
|
EmailTemplatePasskeyChange: () => EmailTemplatePasskeyChange
|
|
62
67
|
});
|
|
63
68
|
function EmailTemplatePasskeyChange({
|
|
@@ -118,14 +123,14 @@ function EmailTemplatePasskeyChange({
|
|
|
118
123
|
] }) }) }) })
|
|
119
124
|
] });
|
|
120
125
|
}
|
|
121
|
-
var
|
|
122
|
-
"components/email/
|
|
126
|
+
var init_passkey_changed = __esm({
|
|
127
|
+
"components/email/security/passkey-changed.tsx"() {
|
|
123
128
|
}
|
|
124
129
|
});
|
|
125
130
|
|
|
126
|
-
// components/email/
|
|
127
|
-
var
|
|
128
|
-
__export(
|
|
131
|
+
// components/email/auth/reset-password.tsx
|
|
132
|
+
var reset_password_exports = {};
|
|
133
|
+
__export(reset_password_exports, {
|
|
129
134
|
EmailTemplateResetPassword: () => EmailTemplateResetPassword
|
|
130
135
|
});
|
|
131
136
|
function EmailTemplateResetPassword({ firstName, url }) {
|
|
@@ -162,14 +167,14 @@ function EmailTemplateResetPassword({ firstName, url }) {
|
|
|
162
167
|
] }) }) })
|
|
163
168
|
] });
|
|
164
169
|
}
|
|
165
|
-
var
|
|
166
|
-
"components/email/
|
|
170
|
+
var init_reset_password = __esm({
|
|
171
|
+
"components/email/auth/reset-password.tsx"() {
|
|
167
172
|
}
|
|
168
173
|
});
|
|
169
174
|
|
|
170
|
-
// components/email/
|
|
171
|
-
var
|
|
172
|
-
__export(
|
|
175
|
+
// components/email/auth/verify-email.tsx
|
|
176
|
+
var verify_email_exports = {};
|
|
177
|
+
__export(verify_email_exports, {
|
|
173
178
|
EmailTemplateVerifyEmail: () => EmailTemplateVerifyEmail
|
|
174
179
|
});
|
|
175
180
|
function EmailTemplateVerifyEmail({ firstName, url }) {
|
|
@@ -198,8 +203,8 @@ function EmailTemplateVerifyEmail({ firstName, url }) {
|
|
|
198
203
|
] }) }) }) })
|
|
199
204
|
] });
|
|
200
205
|
}
|
|
201
|
-
var
|
|
202
|
-
"components/email/
|
|
206
|
+
var init_verify_email = __esm({
|
|
207
|
+
"components/email/auth/verify-email.tsx"() {
|
|
203
208
|
}
|
|
204
209
|
});
|
|
205
210
|
|
|
@@ -223,12 +228,11 @@ __export(schema_exports, {
|
|
|
223
228
|
verifications: () => verifications
|
|
224
229
|
});
|
|
225
230
|
|
|
226
|
-
// lib/maintenance.ts
|
|
231
|
+
// lib/config/maintenance.ts
|
|
227
232
|
var DEFAULT_MAINTENANCE_EXEMPT_PATHS = [
|
|
228
233
|
"/",
|
|
229
234
|
"/features",
|
|
230
235
|
"/changelog",
|
|
231
|
-
"/changelog-template",
|
|
232
236
|
"/privacy",
|
|
233
237
|
"/terms"
|
|
234
238
|
];
|
|
@@ -291,7 +295,10 @@ var sessions = pgCore.pgTable("session", {
|
|
|
291
295
|
// Set by better-auth's admin plugin while this session is an admin
|
|
292
296
|
// impersonating another user; holds the impersonating admin's user id.
|
|
293
297
|
impersonatedBy: pgCore.text("impersonatedBy")
|
|
294
|
-
})
|
|
298
|
+
}, (table) => [
|
|
299
|
+
// Read by userId on every login (session count), ban/delete and the admin sessions view.
|
|
300
|
+
pgCore.index("session_user_idx").on(table.userId)
|
|
301
|
+
]);
|
|
295
302
|
var accounts = pgCore.pgTable("account", {
|
|
296
303
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
297
304
|
accountId: pgCore.text("accountId").notNull(),
|
|
@@ -340,7 +347,10 @@ var verifications = pgCore.pgTable("verification", {
|
|
|
340
347
|
});
|
|
341
348
|
var activityLogs = pgCore.pgTable("activity_log", {
|
|
342
349
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
343
|
-
|
|
350
|
+
// SET NULL, not cascade: deleting an admin must not erase the audit trail of
|
|
351
|
+
// what they did. actorEmail keeps who it was once the user row is gone.
|
|
352
|
+
userId: pgCore.text("userId").references(() => users.id, { onDelete: "set null" }),
|
|
353
|
+
actorEmail: pgCore.text("actorEmail"),
|
|
344
354
|
action: ActivityActionEnum("action").notNull(),
|
|
345
355
|
description: pgCore.text("description").notNull(),
|
|
346
356
|
ipAddress: pgCore.text("ipAddress"),
|
|
@@ -356,7 +366,11 @@ var activityLogs = pgCore.pgTable("activity_log", {
|
|
|
356
366
|
country: pgCore.text("country"),
|
|
357
367
|
city: pgCore.text("city"),
|
|
358
368
|
createdAt: pgCore.timestamp("createdAt").notNull().defaultNow()
|
|
359
|
-
})
|
|
369
|
+
}, (table) => [
|
|
370
|
+
// Per-user history, and the admin log's newest-first ordering.
|
|
371
|
+
pgCore.index("activity_log_user_created_idx").on(table.userId, table.createdAt),
|
|
372
|
+
pgCore.index("activity_log_created_idx").on(table.createdAt)
|
|
373
|
+
]);
|
|
360
374
|
var deviceFingerprints = pgCore.pgTable("device_fingerprint", {
|
|
361
375
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
362
376
|
userId: pgCore.text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
@@ -471,7 +485,9 @@ var envSchema = zod.z.object({
|
|
|
471
485
|
RESEND_MARKETING_SEGMENT_ID: zod.z.string().default(""),
|
|
472
486
|
// Sender for every transactional email. Must be on a domain verified in
|
|
473
487
|
// your Resend account.
|
|
474
|
-
|
|
488
|
+
// Resend's shared sandbox sender: works without a verified domain but only
|
|
489
|
+
// delivers to your own Resend account email. Set your verified domain for real use.
|
|
490
|
+
EMAIL_FROM: zod.z.string().default("Acme <onboarding@resend.dev>"),
|
|
475
491
|
// Display name for this deployment — shown as the authenticator-app label
|
|
476
492
|
// (2FA issuer) and the passkey relying-party name. Consuming projects set
|
|
477
493
|
// this in their own .env; defaults to the template name.
|
|
@@ -481,6 +497,9 @@ var envSchema = zod.z.object({
|
|
|
481
497
|
// a comma-separated list and sends through Resend (needs RESEND_API_KEY).
|
|
482
498
|
FEEDBACK_DISCORD_WEBHOOK_URL: zod.z.string().default(""),
|
|
483
499
|
FEEDBACK_EMAIL: zod.z.string().default(""),
|
|
500
|
+
// Seconds between feedback messages per user (default 30, 0 = off). Read
|
|
501
|
+
// straight from process.env in lib/feedback/route.ts; listed here for docs.
|
|
502
|
+
FEEDBACK_COOLDOWN_SECONDS: zod.z.string().default("30"),
|
|
484
503
|
// Web Push (example, see lib/push.ts). Generate keys with
|
|
485
504
|
// `bunx web-push generate-vapid-keys`. Blank = the notifications card is hidden.
|
|
486
505
|
// The public key is also read in the browser as NEXT_PUBLIC_VAPID_PUBLIC_KEY.
|
|
@@ -497,7 +516,12 @@ var envSchema = zod.z.object({
|
|
|
497
516
|
DB_DRIVER: zod.z.enum(["pg", "neon"]).default("pg"),
|
|
498
517
|
// Only relevant when DB_DRIVER=pg — whether the target Postgres server has SSL
|
|
499
518
|
// enabled. Self-hosted Postgres (e.g. via Docker/Dokploy) typically does not.
|
|
500
|
-
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true")
|
|
519
|
+
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true"),
|
|
520
|
+
// With DATABASE_SSL=true the server certificate is verified. Set the CA (PEM,
|
|
521
|
+
// "\n" for newlines) for a self-signed or private CA; DATABASE_SSL_INSECURE=true
|
|
522
|
+
// skips verification (encrypts only). Both are read in config/pg-ssl.ts.
|
|
523
|
+
DATABASE_SSL_CA: zod.z.string().default(""),
|
|
524
|
+
DATABASE_SSL_INSECURE: zod.z.string().default("false")
|
|
501
525
|
});
|
|
502
526
|
|
|
503
527
|
// config/env.ts
|
|
@@ -511,24 +535,47 @@ if (!results.success) {
|
|
|
511
535
|
}
|
|
512
536
|
var config = results.data;
|
|
513
537
|
|
|
538
|
+
// config/pg-ssl.ts
|
|
539
|
+
function pgSslOptions() {
|
|
540
|
+
var _a;
|
|
541
|
+
if (process.env.DATABASE_SSL_INSECURE === "true") return { rejectUnauthorized: false };
|
|
542
|
+
const ca = (_a = process.env.DATABASE_SSL_CA) == null ? void 0 : _a.replace(/\\n/g, "\n");
|
|
543
|
+
return __spreadValues({ rejectUnauthorized: true }, ca ? { ca } : {});
|
|
544
|
+
}
|
|
545
|
+
|
|
514
546
|
// server/db/index.ts
|
|
515
547
|
var db;
|
|
516
548
|
if (config.DB_DRIVER === "pg") {
|
|
517
549
|
const pool = new pg.Pool({
|
|
518
550
|
connectionString: config.DATABASE_URL,
|
|
519
|
-
ssl: config.DATABASE_SSL ?
|
|
551
|
+
ssl: config.DATABASE_SSL ? pgSslOptions() : void 0,
|
|
552
|
+
// pg waits forever by default; a hung DB would otherwise freeze every request (proxy reads settings).
|
|
553
|
+
connectionTimeoutMillis: 5e3,
|
|
554
|
+
query_timeout: 15e3
|
|
555
|
+
// roomy enough for the 10k-row exports
|
|
520
556
|
});
|
|
521
557
|
db = nodePostgres.drizzle(pool, {
|
|
522
558
|
schema: schema_exports,
|
|
523
|
-
logger:
|
|
559
|
+
logger: process.env.NODE_ENV === "development"
|
|
524
560
|
});
|
|
525
561
|
console.log("\u{1F7E1} Using PostgreSQL (pg) driver");
|
|
526
|
-
} else if (config.DB_DRIVER === "neon") {
|
|
527
|
-
const sql4 = serverless.neon(config.DATABASE_URL);
|
|
528
|
-
db = neonHttp.drizzle(sql4, { schema: schema_exports, logger: true });
|
|
529
|
-
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
530
562
|
} else {
|
|
531
|
-
|
|
563
|
+
serverless.neonConfig.fetchFunction = (url, init) => fetch(url, __spreadProps(__spreadValues({}, init), { signal: AbortSignal.timeout(15e3) }));
|
|
564
|
+
const sql6 = serverless.neon(config.DATABASE_URL);
|
|
565
|
+
db = neonHttp.drizzle(sql6, { schema: schema_exports, logger: process.env.NODE_ENV === "development" });
|
|
566
|
+
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// node_modules/@better-auth/utils/dist/bytes.mjs
|
|
570
|
+
function toBufferSource(data) {
|
|
571
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
572
|
+
if (!ArrayBuffer.isView(data)) return data;
|
|
573
|
+
if (data.buffer instanceof ArrayBuffer) return data;
|
|
574
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
|
|
575
|
+
}
|
|
576
|
+
function toUint8Array(data) {
|
|
577
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
578
|
+
return new Uint8Array(data);
|
|
532
579
|
}
|
|
533
580
|
|
|
534
581
|
// node_modules/@better-auth/utils/dist/base32.mjs
|
|
@@ -537,9 +584,7 @@ function getAlphabet(hex2) {
|
|
|
537
584
|
}
|
|
538
585
|
function createDecodeMap(alphabet) {
|
|
539
586
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
540
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
541
|
-
decodeMap.set(alphabet[i], i);
|
|
542
|
-
}
|
|
587
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
543
588
|
return decodeMap;
|
|
544
589
|
}
|
|
545
590
|
function base32Encode(data, alphabet, padding) {
|
|
@@ -554,9 +599,7 @@ function base32Encode(data, alphabet, padding) {
|
|
|
554
599
|
result += alphabet[buffer >> shift & 31];
|
|
555
600
|
}
|
|
556
601
|
}
|
|
557
|
-
if (shift > 0)
|
|
558
|
-
result += alphabet[buffer << 5 - shift & 31];
|
|
559
|
-
}
|
|
602
|
+
if (shift > 0) result += alphabet[buffer << 5 - shift & 31];
|
|
560
603
|
if (padding) {
|
|
561
604
|
const padCount = (8 - result.length % 8) % 8;
|
|
562
605
|
result += "=".repeat(padCount);
|
|
@@ -569,12 +612,9 @@ function base32Decode(data, alphabet) {
|
|
|
569
612
|
let buffer = 0;
|
|
570
613
|
let bitsCollected = 0;
|
|
571
614
|
for (const char of data) {
|
|
572
|
-
if (char === "=")
|
|
573
|
-
break;
|
|
615
|
+
if (char === "=") break;
|
|
574
616
|
const value = decodeMap.get(char);
|
|
575
|
-
if (value === void 0) {
|
|
576
|
-
throw new Error(`Invalid Base32 character: ${char}`);
|
|
577
|
-
}
|
|
617
|
+
if (value === void 0) throw new Error(`Invalid Base32 character: ${char}`);
|
|
578
618
|
buffer = buffer << 5 | value;
|
|
579
619
|
bitsCollected += 5;
|
|
580
620
|
while (bitsCollected >= 8) {
|
|
@@ -586,68 +626,34 @@ function base32Decode(data, alphabet) {
|
|
|
586
626
|
}
|
|
587
627
|
var base32 = {
|
|
588
628
|
/**
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
629
|
+
* Encodes data into a Base32 string.
|
|
630
|
+
* @param data - The data to encode (ArrayBuffer, number-based TypedArray, or string).
|
|
631
|
+
* @param options - Encoding options.
|
|
632
|
+
* @returns The Base32 encoded string.
|
|
633
|
+
*/
|
|
594
634
|
encode(data, options = {}) {
|
|
595
635
|
var _a;
|
|
596
636
|
const alphabet = getAlphabet();
|
|
597
|
-
|
|
598
|
-
return base32Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
637
|
+
return base32Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
599
638
|
},
|
|
600
639
|
/**
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
640
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
641
|
+
* @param data - The Base32 encoded string or ArrayBuffer/TypedArray.
|
|
642
|
+
* @returns The decoded Uint8Array.
|
|
643
|
+
*/
|
|
605
644
|
decode(data) {
|
|
606
|
-
if (typeof data !== "string")
|
|
607
|
-
data = new TextDecoder().decode(data);
|
|
608
|
-
}
|
|
645
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
609
646
|
const alphabet = getAlphabet();
|
|
610
647
|
return base32Decode(data, alphabet);
|
|
611
648
|
}
|
|
612
649
|
};
|
|
613
650
|
|
|
614
|
-
// node_modules/@better-auth/utils/dist/
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
}
|
|
621
|
-
if (data.byteLength === 0) {
|
|
622
|
-
return "";
|
|
623
|
-
}
|
|
624
|
-
const buffer = new Uint8Array(data);
|
|
625
|
-
let result = "";
|
|
626
|
-
for (const byte of buffer) {
|
|
627
|
-
result += byte.toString(16).padStart(2, "0");
|
|
628
|
-
}
|
|
629
|
-
return result;
|
|
630
|
-
},
|
|
631
|
-
decode: (data) => {
|
|
632
|
-
if (!data) {
|
|
633
|
-
return "";
|
|
634
|
-
}
|
|
635
|
-
if (typeof data === "string") {
|
|
636
|
-
if (data.length % 2 !== 0) {
|
|
637
|
-
throw new Error("Invalid hexadecimal string");
|
|
638
|
-
}
|
|
639
|
-
if (!new RegExp(`^[${hexadecimal}]+$`).test(data)) {
|
|
640
|
-
throw new Error("Invalid hexadecimal string");
|
|
641
|
-
}
|
|
642
|
-
const result = new Uint8Array(data.length / 2);
|
|
643
|
-
for (let i = 0; i < data.length; i += 2) {
|
|
644
|
-
result[i / 2] = parseInt(data.slice(i, i + 2), 16);
|
|
645
|
-
}
|
|
646
|
-
return new TextDecoder().decode(result);
|
|
647
|
-
}
|
|
648
|
-
return new TextDecoder().decode(data);
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
+
// node_modules/@better-auth/utils/dist/index.mjs
|
|
652
|
+
function getWebcryptoSubtle() {
|
|
653
|
+
const cr = typeof globalThis !== "undefined" && globalThis.crypto;
|
|
654
|
+
if (cr && typeof cr.subtle === "object" && cr.subtle != null) return cr.subtle;
|
|
655
|
+
throw new Error("crypto.subtle must be defined");
|
|
656
|
+
}
|
|
651
657
|
|
|
652
658
|
// node_modules/@better-auth/utils/dist/base64.mjs
|
|
653
659
|
function getAlphabet2(urlSafe) {
|
|
@@ -665,9 +671,7 @@ function base64Encode(data, alphabet, padding) {
|
|
|
665
671
|
result += alphabet[buffer >> shift & 63];
|
|
666
672
|
}
|
|
667
673
|
}
|
|
668
|
-
if (shift > 0)
|
|
669
|
-
result += alphabet[buffer << 6 - shift & 63];
|
|
670
|
-
}
|
|
674
|
+
if (shift > 0) result += alphabet[buffer << 6 - shift & 63];
|
|
671
675
|
if (padding) {
|
|
672
676
|
const padCount = (4 - result.length % 4) % 4;
|
|
673
677
|
result += "=".repeat(padCount);
|
|
@@ -676,19 +680,14 @@ function base64Encode(data, alphabet, padding) {
|
|
|
676
680
|
}
|
|
677
681
|
function base64Decode(data, alphabet) {
|
|
678
682
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
679
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
680
|
-
decodeMap.set(alphabet[i], i);
|
|
681
|
-
}
|
|
683
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
682
684
|
const result = [];
|
|
683
685
|
let buffer = 0;
|
|
684
686
|
let bitsCollected = 0;
|
|
685
687
|
for (const char of data) {
|
|
686
|
-
if (char === "=")
|
|
687
|
-
break;
|
|
688
|
+
if (char === "=") break;
|
|
688
689
|
const value = decodeMap.get(char);
|
|
689
|
-
if (value === void 0) {
|
|
690
|
-
throw new Error(`Invalid Base64 character: ${char}`);
|
|
691
|
-
}
|
|
690
|
+
if (value === void 0) throw new Error(`Invalid Base64 character: ${char}`);
|
|
692
691
|
buffer = buffer << 6 | value;
|
|
693
692
|
bitsCollected += 6;
|
|
694
693
|
if (bitsCollected >= 8) {
|
|
@@ -702,15 +701,11 @@ var base64 = {
|
|
|
702
701
|
encode(data, options = {}) {
|
|
703
702
|
var _a;
|
|
704
703
|
const alphabet = getAlphabet2(false);
|
|
705
|
-
|
|
706
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
704
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
707
705
|
},
|
|
708
706
|
decode(data) {
|
|
709
|
-
if (typeof data !== "string")
|
|
710
|
-
|
|
711
|
-
}
|
|
712
|
-
const urlSafe = data.includes("-") || data.includes("_");
|
|
713
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
707
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
708
|
+
const alphabet = getAlphabet2(data.includes("-") || data.includes("_"));
|
|
714
709
|
return base64Decode(data, alphabet);
|
|
715
710
|
}
|
|
716
711
|
};
|
|
@@ -718,152 +713,142 @@ var base64Url = {
|
|
|
718
713
|
encode(data, options = {}) {
|
|
719
714
|
var _a;
|
|
720
715
|
const alphabet = getAlphabet2(true);
|
|
721
|
-
|
|
722
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
716
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
723
717
|
},
|
|
724
718
|
decode(data) {
|
|
725
|
-
|
|
726
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
727
|
-
return base64Decode(data, alphabet);
|
|
719
|
+
return base64Decode(data, getAlphabet2(data.includes("-") || data.includes("_")));
|
|
728
720
|
}
|
|
729
721
|
};
|
|
730
722
|
|
|
731
|
-
// node_modules/@
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
723
|
+
// node_modules/@noble/hashes/utils.js
|
|
724
|
+
var hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
725
|
+
// @ts-ignore
|
|
726
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
727
|
+
))();
|
|
728
|
+
function asciiToBase16(ch) {
|
|
729
|
+
return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
|
|
737
730
|
}
|
|
731
|
+
function hexToBytes(hex2) {
|
|
732
|
+
if (typeof hex2 !== "string")
|
|
733
|
+
throw new TypeError("hex string expected, got " + typeof hex2);
|
|
734
|
+
if (hasHexBuiltin) {
|
|
735
|
+
try {
|
|
736
|
+
return Uint8Array.fromHex(hex2);
|
|
737
|
+
} catch (error) {
|
|
738
|
+
if (error instanceof SyntaxError)
|
|
739
|
+
throw new RangeError(error.message);
|
|
740
|
+
throw error;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
const hl = hex2.length;
|
|
744
|
+
const al = hl / 2;
|
|
745
|
+
if (hl % 2)
|
|
746
|
+
throw new RangeError("hex string expected, got unpadded hex of length " + hl);
|
|
747
|
+
const array = new Uint8Array(al);
|
|
748
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
749
|
+
const n1 = asciiToBase16(hex2.charCodeAt(hi));
|
|
750
|
+
const n2 = asciiToBase16(hex2.charCodeAt(hi + 1));
|
|
751
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
752
|
+
const char = hex2[hi] + hex2[hi + 1];
|
|
753
|
+
throw new RangeError('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
754
|
+
}
|
|
755
|
+
array[ai] = n1 * 16 + n2;
|
|
756
|
+
}
|
|
757
|
+
return array;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// node_modules/@better-auth/utils/dist/hex.mjs
|
|
761
|
+
var toBytes = (data) => hexToBytes(data);
|
|
762
|
+
var hex = {
|
|
763
|
+
encode: (data) => {
|
|
764
|
+
const buffer = toUint8Array(data);
|
|
765
|
+
if (buffer.byteLength === 0) return "";
|
|
766
|
+
let result = "";
|
|
767
|
+
for (const byte of buffer) result += byte.toString(16).padStart(2, "0");
|
|
768
|
+
return result;
|
|
769
|
+
},
|
|
770
|
+
decode: (data) => {
|
|
771
|
+
if (!data) return "";
|
|
772
|
+
if (typeof data === "string") return new TextDecoder().decode(toBytes(data));
|
|
773
|
+
return new TextDecoder().decode(data);
|
|
774
|
+
},
|
|
775
|
+
toBytes
|
|
776
|
+
};
|
|
738
777
|
|
|
739
778
|
// node_modules/@better-auth/utils/dist/hmac.mjs
|
|
740
779
|
var createHMAC = (algorithm = "SHA-256", encoding = "none") => {
|
|
741
|
-
const
|
|
780
|
+
const hmac2 = {
|
|
742
781
|
importKey: async (key, keyUsage) => {
|
|
743
|
-
return getWebcryptoSubtle().importKey(
|
|
744
|
-
"
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
false,
|
|
748
|
-
[keyUsage]
|
|
749
|
-
);
|
|
782
|
+
return getWebcryptoSubtle().importKey("raw", toBufferSource(key), {
|
|
783
|
+
name: "HMAC",
|
|
784
|
+
hash: { name: algorithm }
|
|
785
|
+
}, false, [keyUsage]);
|
|
750
786
|
},
|
|
751
787
|
sign: async (hmacKey, data) => {
|
|
752
|
-
if (typeof hmacKey === "string")
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
hmacKey,
|
|
758
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
759
|
-
);
|
|
760
|
-
if (encoding === "hex") {
|
|
761
|
-
return hex.encode(signature);
|
|
762
|
-
}
|
|
763
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
764
|
-
return base64Url.encode(signature, {
|
|
765
|
-
padding: encoding !== "base64urlnopad"
|
|
766
|
-
});
|
|
767
|
-
}
|
|
788
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "sign");
|
|
789
|
+
const signature = await getWebcryptoSubtle().sign("HMAC", hmacKey, toBufferSource(data));
|
|
790
|
+
if (encoding === "hex") return hex.encode(signature);
|
|
791
|
+
if (encoding === "base64") return base64.encode(signature);
|
|
792
|
+
if (encoding === "base64url" || encoding === "base64urlnopad") return base64Url.encode(signature, { padding: encoding !== "base64urlnopad" });
|
|
768
793
|
return signature;
|
|
769
794
|
},
|
|
770
795
|
verify: async (hmacKey, data, signature) => {
|
|
771
|
-
if (typeof hmacKey === "string")
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
signature = hex.decode(signature);
|
|
776
|
-
}
|
|
777
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
778
|
-
signature = await base64.decode(signature);
|
|
779
|
-
}
|
|
780
|
-
return getWebcryptoSubtle().verify(
|
|
781
|
-
"HMAC",
|
|
782
|
-
hmacKey,
|
|
783
|
-
typeof signature === "string" ? new TextEncoder().encode(signature) : signature,
|
|
784
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
785
|
-
);
|
|
796
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "verify");
|
|
797
|
+
if (encoding === "hex") signature = typeof signature === "string" ? hex.toBytes(signature) : signature;
|
|
798
|
+
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") signature = await base64.decode(signature);
|
|
799
|
+
return getWebcryptoSubtle().verify("HMAC", hmacKey, toBufferSource(signature), toBufferSource(data));
|
|
786
800
|
}
|
|
787
801
|
};
|
|
788
|
-
return
|
|
802
|
+
return hmac2;
|
|
789
803
|
};
|
|
790
804
|
|
|
791
805
|
// node_modules/@better-auth/utils/dist/otp.mjs
|
|
792
806
|
var defaultPeriod = 30;
|
|
793
807
|
var defaultDigits = 6;
|
|
808
|
+
var hmac = createHMAC("SHA-1");
|
|
794
809
|
function constantTimeEqualOTP(input, expected) {
|
|
795
810
|
let difference = input.length ^ expected.length;
|
|
796
|
-
for (let i = 0; i < expected.length; i++)
|
|
797
|
-
difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
798
|
-
}
|
|
811
|
+
for (let i = 0; i < expected.length; i++) difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
799
812
|
return difference === 0;
|
|
800
813
|
}
|
|
801
|
-
async function generateHOTP(
|
|
802
|
-
counter,
|
|
803
|
-
digits,
|
|
804
|
-
hash = "SHA-1"
|
|
805
|
-
}) {
|
|
814
|
+
async function generateHOTP(key, { counter, digits }) {
|
|
806
815
|
const _digits = digits != null ? digits : defaultDigits;
|
|
807
|
-
if (_digits < 1 || _digits > 8)
|
|
808
|
-
|
|
809
|
-
}
|
|
810
|
-
const buffer = new ArrayBuffer(8);
|
|
816
|
+
if (_digits < 1 || _digits > 8) throw new TypeError("Digits must be between 1 and 8");
|
|
817
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
811
818
|
new DataView(buffer).setBigUint64(0, BigInt(counter), false);
|
|
812
819
|
const bytes = new Uint8Array(buffer);
|
|
813
|
-
const
|
|
820
|
+
const signature = await hmac.sign(key, bytes);
|
|
821
|
+
const hmacResult = new Uint8Array(signature);
|
|
814
822
|
const offset = hmacResult[hmacResult.length - 1] & 15;
|
|
815
|
-
|
|
816
|
-
const otp = truncated % 10 ** _digits;
|
|
817
|
-
return otp.toString().padStart(_digits, "0");
|
|
823
|
+
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");
|
|
818
824
|
}
|
|
819
|
-
async function generateTOTP(
|
|
825
|
+
async function generateTOTP(key, options) {
|
|
820
826
|
var _a, _b;
|
|
821
827
|
const digits = (_a = options == null ? void 0 : options.digits) != null ? _a : defaultDigits;
|
|
822
|
-
const
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
828
|
+
const milliseconds = ((_b = options == null ? void 0 : options.period) != null ? _b : defaultPeriod) * 1e3;
|
|
829
|
+
return await generateHOTP(key, {
|
|
830
|
+
counter: Math.floor(Date.now() / milliseconds),
|
|
831
|
+
digits
|
|
832
|
+
});
|
|
826
833
|
}
|
|
827
|
-
async function verifyTOTP(otp, {
|
|
828
|
-
window = 1,
|
|
829
|
-
digits = defaultDigits,
|
|
830
|
-
secret,
|
|
831
|
-
period = defaultPeriod
|
|
832
|
-
}) {
|
|
834
|
+
async function verifyTOTP(otp, { window = 1, digits = defaultDigits, key, period = defaultPeriod }) {
|
|
833
835
|
const milliseconds = period * 1e3;
|
|
834
836
|
const counter = Math.floor(Date.now() / milliseconds);
|
|
835
837
|
let matched = false;
|
|
836
|
-
for (let i = -window; i <= window; i++) {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
});
|
|
841
|
-
matched = constantTimeEqualOTP(otp, generatedOTP) || matched;
|
|
842
|
-
}
|
|
838
|
+
for (let i = -window; i <= window; i++) matched = constantTimeEqualOTP(otp, await generateHOTP(key, {
|
|
839
|
+
counter: counter + i,
|
|
840
|
+
digits
|
|
841
|
+
})) || matched;
|
|
843
842
|
return matched;
|
|
844
843
|
}
|
|
845
|
-
function generateQRCode({
|
|
846
|
-
issuer
|
|
847
|
-
account,
|
|
848
|
-
secret,
|
|
849
|
-
digits = defaultDigits,
|
|
850
|
-
period = defaultPeriod
|
|
851
|
-
}) {
|
|
852
|
-
const encodedIssuer = encodeURIComponent(issuer);
|
|
853
|
-
const encodedAccountName = encodeURIComponent(account);
|
|
854
|
-
const baseURI = `otpauth://totp/${encodedIssuer}:${encodedAccountName}`;
|
|
844
|
+
function generateQRCode({ issuer, account, secret, digits = defaultDigits, period = defaultPeriod }) {
|
|
845
|
+
const baseURI = `otpauth://totp/${encodeURIComponent(issuer)}:${encodeURIComponent(account)}`;
|
|
855
846
|
const params = new URLSearchParams({
|
|
856
|
-
secret: base32.encode(secret, {
|
|
857
|
-
padding: false
|
|
858
|
-
}),
|
|
847
|
+
secret: base32.encode(secret, { padding: false }),
|
|
859
848
|
issuer
|
|
860
849
|
});
|
|
861
|
-
if (digits !== void 0)
|
|
862
|
-
|
|
863
|
-
}
|
|
864
|
-
if (period !== void 0) {
|
|
865
|
-
params.set("period", period.toString());
|
|
866
|
-
}
|
|
850
|
+
if (digits !== void 0) params.set("digits", digits.toString());
|
|
851
|
+
if (period !== void 0) params.set("period", period.toString());
|
|
867
852
|
return `${baseURI}?${params.toString()}`;
|
|
868
853
|
}
|
|
869
854
|
var createOTP = (secret, opts) => {
|
|
@@ -871,14 +856,38 @@ var createOTP = (secret, opts) => {
|
|
|
871
856
|
const digits = (_a = void 0 ) != null ? _a : defaultDigits;
|
|
872
857
|
const period = (_b = void 0 ) != null ? _b : defaultPeriod;
|
|
873
858
|
return {
|
|
874
|
-
hotp: (counter) =>
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
859
|
+
hotp: async (counter) => {
|
|
860
|
+
return generateHOTP(await hmac.importKey(secret, "sign"), {
|
|
861
|
+
counter,
|
|
862
|
+
digits
|
|
863
|
+
});
|
|
864
|
+
},
|
|
865
|
+
totp: async () => {
|
|
866
|
+
return generateTOTP(await hmac.importKey(secret, "sign"), {
|
|
867
|
+
digits,
|
|
868
|
+
period
|
|
869
|
+
});
|
|
870
|
+
},
|
|
871
|
+
verify: async (otp, options) => {
|
|
872
|
+
return verifyTOTP(otp, __spreadValues({
|
|
873
|
+
key: await hmac.importKey(secret, "sign"),
|
|
874
|
+
digits,
|
|
875
|
+
period
|
|
876
|
+
}, options));
|
|
877
|
+
},
|
|
878
|
+
url: (issuer, account) => {
|
|
879
|
+
return generateQRCode({
|
|
880
|
+
issuer,
|
|
881
|
+
account,
|
|
882
|
+
secret,
|
|
883
|
+
digits,
|
|
884
|
+
period
|
|
885
|
+
});
|
|
886
|
+
}
|
|
878
887
|
};
|
|
879
888
|
};
|
|
880
889
|
|
|
881
|
-
// lib/two-factor.ts
|
|
890
|
+
// lib/auth/two-factor.ts
|
|
882
891
|
var CHALLENGED_PATHS = ["/callback/:id", "/one-tap/callback"];
|
|
883
892
|
var CODE_REQUIRED_PATHS = ["/two-factor/disable", "/two-factor/generate-backup-codes"];
|
|
884
893
|
function twoFactorPlugins(baseURL, { issuer, passwordless = false, challengeAfterOAuth = false }) {
|
|
@@ -951,6 +960,8 @@ async function logActivity({
|
|
|
951
960
|
try {
|
|
952
961
|
await db.insert(activityLogs).values({
|
|
953
962
|
userId,
|
|
963
|
+
// Snapshot the email at write time; survives deletion of the user row.
|
|
964
|
+
actorEmail: drizzleOrm.sql`(select "email" from "user" where "id" = ${userId})`,
|
|
954
965
|
action,
|
|
955
966
|
description,
|
|
956
967
|
ipAddress: ipAddress || null,
|
|
@@ -971,7 +982,7 @@ var countryNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
|
971
982
|
function getClientIp(headers2) {
|
|
972
983
|
var _a;
|
|
973
984
|
const forwardedFor = headers2 == null ? void 0 : headers2.get("x-forwarded-for");
|
|
974
|
-
if (forwardedFor) return forwardedFor.split(",")
|
|
985
|
+
if (forwardedFor) return forwardedFor.split(",").at(-1).trim();
|
|
975
986
|
return (_a = headers2 == null ? void 0 : headers2.get("x-real-ip")) != null ? _a : null;
|
|
976
987
|
}
|
|
977
988
|
function parseUserAgent(userAgent) {
|
|
@@ -1010,11 +1021,21 @@ function formatLocation({ country, city }) {
|
|
|
1010
1021
|
return [city, country].filter(Boolean).join(", ");
|
|
1011
1022
|
}
|
|
1012
1023
|
|
|
1013
|
-
// lib/cookie-names.ts
|
|
1024
|
+
// lib/security/cookie-names.ts
|
|
1014
1025
|
var LOGIN_REFERRER_COOKIE = "login_referrer";
|
|
1015
1026
|
var DEVICE_FINGERPRINT_HEADER = "x-device-fingerprint";
|
|
1016
1027
|
|
|
1017
|
-
// lib/auth-
|
|
1028
|
+
// lib/auth/base-url.ts
|
|
1029
|
+
function getBaseUrl() {
|
|
1030
|
+
const url = process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
|
|
1031
|
+
return url.replace(/\/+$/, "");
|
|
1032
|
+
}
|
|
1033
|
+
function otherActiveAdminExists(excludeIds) {
|
|
1034
|
+
const ids = drizzleOrm.sql.join(excludeIds.map((id) => drizzleOrm.sql`${id}`), drizzleOrm.sql`, `);
|
|
1035
|
+
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`;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// lib/auth/throttle-limits.ts
|
|
1018
1039
|
var WINDOW_MS = 15 * 60 * 1e3;
|
|
1019
1040
|
var MAX = 10;
|
|
1020
1041
|
var MAX_IP = MAX * 3;
|
|
@@ -1025,7 +1046,7 @@ function isOverLimit(row, now, max = MAX) {
|
|
|
1025
1046
|
return row.count >= max;
|
|
1026
1047
|
}
|
|
1027
1048
|
|
|
1028
|
-
// lib/auth
|
|
1049
|
+
// lib/auth/throttle.ts
|
|
1029
1050
|
async function isDeviceThrottled(fingerprint, max) {
|
|
1030
1051
|
try {
|
|
1031
1052
|
const [row] = await db.select({ count: authThrottle.count, windowStart: authThrottle.windowStart }).from(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint)).limit(1);
|
|
@@ -1049,8 +1070,10 @@ async function recordDeviceAttempt(fingerprint, meta) {
|
|
|
1049
1070
|
await db.insert(authThrottle).values(__spreadValues({ fingerprint, count: 1, windowStart: now }, seen)).onConflictDoUpdate({
|
|
1050
1071
|
target: authThrottle.fingerprint,
|
|
1051
1072
|
set: __spreadValues({
|
|
1052
|
-
|
|
1053
|
-
|
|
1073
|
+
// ISO strings, not Dates: pg sends a raw Date as server-local time, which a
|
|
1074
|
+
// tz-less `timestamp` column (stored as UTC) misreads on any non-UTC host.
|
|
1075
|
+
count: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then 1 else ${authThrottle.count} + 1 end`,
|
|
1076
|
+
windowStart: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then ${now.toISOString()} else ${authThrottle.windowStart} end`
|
|
1054
1077
|
}, seen)
|
|
1055
1078
|
});
|
|
1056
1079
|
} catch (error) {
|
|
@@ -1069,15 +1092,9 @@ async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
|
1069
1092
|
console.error("auth-throttle prune failed", error);
|
|
1070
1093
|
}
|
|
1071
1094
|
}
|
|
1072
|
-
async function clearDeviceThrottle(fingerprint) {
|
|
1073
|
-
try {
|
|
1074
|
-
await db.delete(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint));
|
|
1075
|
-
} catch (error) {
|
|
1076
|
-
console.error("auth-throttle clear failed", error);
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
1095
|
var SETTINGS_ROW_ID = "default";
|
|
1080
1096
|
var CACHE_TTL_MS = 1e4;
|
|
1097
|
+
var FAILURE_CACHE_TTL_MS = 5e3;
|
|
1081
1098
|
var cached = null;
|
|
1082
1099
|
function fallbackSettings() {
|
|
1083
1100
|
return {
|
|
@@ -1120,7 +1137,9 @@ async function getSystemSettings() {
|
|
|
1120
1137
|
return value;
|
|
1121
1138
|
} catch (error) {
|
|
1122
1139
|
console.error("Failed to load system settings, failing open:", error);
|
|
1123
|
-
|
|
1140
|
+
const value = fallbackSettings();
|
|
1141
|
+
cached = { value, expiresAt: now + FAILURE_CACHE_TTL_MS };
|
|
1142
|
+
return value;
|
|
1124
1143
|
}
|
|
1125
1144
|
}
|
|
1126
1145
|
async function getEffectiveAuthFlags() {
|
|
@@ -1177,7 +1196,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1177
1196
|
userAgent: (_b = (_a = ctx.headers) == null ? void 0 : _a.get("user-agent")) != null ? _b : null
|
|
1178
1197
|
});
|
|
1179
1198
|
if (!config.RESEND_API_KEY) return;
|
|
1180
|
-
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (
|
|
1199
|
+
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (init_passkey_changed(), passkey_changed_exports));
|
|
1181
1200
|
await (await getResend()).emails.send({
|
|
1182
1201
|
from: EMAIL_FROM,
|
|
1183
1202
|
to: [user.email],
|
|
@@ -1189,7 +1208,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1189
1208
|
location: formatLocation(lookupGeoLocation(ip)),
|
|
1190
1209
|
ipAddress: ip || "Unknown",
|
|
1191
1210
|
when: (/* @__PURE__ */ new Date()).toUTCString(),
|
|
1192
|
-
manageUrl: `${
|
|
1211
|
+
manageUrl: `${getBaseUrl()}/dashboard/settings`
|
|
1193
1212
|
})
|
|
1194
1213
|
});
|
|
1195
1214
|
} catch (error) {
|
|
@@ -1240,6 +1259,15 @@ async function packageSessionCreated(log, ...[session, context]) {
|
|
|
1240
1259
|
console.error("Failed to log login activity", error);
|
|
1241
1260
|
}
|
|
1242
1261
|
}
|
|
1262
|
+
async function promoteFirstAdmin(user) {
|
|
1263
|
+
var _a;
|
|
1264
|
+
const adminEmail = (_a = process.env.ADMIN_EMAIL) == null ? void 0 : _a.trim().toLowerCase();
|
|
1265
|
+
if (!adminEmail || !user.emailVerified || user.email.toLowerCase() !== adminEmail) return;
|
|
1266
|
+
const [existing] = await db.select({ id: users.id }).from(users).where(drizzleOrm.eq(users.role, "admin")).limit(1);
|
|
1267
|
+
if (existing) return;
|
|
1268
|
+
await db.update(users).set({ role: "admin" }).where(drizzleOrm.eq(users.id, user.id));
|
|
1269
|
+
user.role = "admin";
|
|
1270
|
+
}
|
|
1243
1271
|
function createAuth(overrides = {}) {
|
|
1244
1272
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1245
1273
|
const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
|
|
@@ -1255,7 +1283,7 @@ function createAuth(overrides = {}) {
|
|
|
1255
1283
|
"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: {...} })."
|
|
1256
1284
|
);
|
|
1257
1285
|
}
|
|
1258
|
-
const baseURL =
|
|
1286
|
+
const baseURL = getBaseUrl();
|
|
1259
1287
|
const log = (_a = overrides.logActivity) != null ? _a : logActivity;
|
|
1260
1288
|
const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
|
|
1261
1289
|
issuer: config.APP_NAME,
|
|
@@ -1303,7 +1331,7 @@ function createAuth(overrides = {}) {
|
|
|
1303
1331
|
// callbackURL) — see app/(auth)/forgot-password and reset-password for
|
|
1304
1332
|
// the pages this points at.
|
|
1305
1333
|
async sendResetPassword({ user, url }) {
|
|
1306
|
-
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (
|
|
1334
|
+
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (init_reset_password(), reset_password_exports));
|
|
1307
1335
|
await (await getResend()).emails.send({
|
|
1308
1336
|
from: EMAIL_FROM,
|
|
1309
1337
|
to: [user.email],
|
|
@@ -1319,8 +1347,11 @@ function createAuth(overrides = {}) {
|
|
|
1319
1347
|
// callback that flips users.emailVerified on click.
|
|
1320
1348
|
emailVerification: {
|
|
1321
1349
|
autoSignInAfterVerification: true,
|
|
1350
|
+
async afterEmailVerification(user) {
|
|
1351
|
+
await promoteFirstAdmin(user);
|
|
1352
|
+
},
|
|
1322
1353
|
async sendVerificationEmail({ user, url }) {
|
|
1323
|
-
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (
|
|
1354
|
+
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (init_verify_email(), verify_email_exports));
|
|
1324
1355
|
await (await getResend()).emails.send({
|
|
1325
1356
|
from: EMAIL_FROM,
|
|
1326
1357
|
to: [user.email],
|
|
@@ -1362,6 +1393,7 @@ function createAuth(overrides = {}) {
|
|
|
1362
1393
|
create: {
|
|
1363
1394
|
async after(user, context) {
|
|
1364
1395
|
var _a2, _b2, _c2, _d2;
|
|
1396
|
+
await promoteFirstAdmin(user);
|
|
1365
1397
|
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));
|
|
1366
1398
|
}
|
|
1367
1399
|
}
|
|
@@ -1385,7 +1417,7 @@ function createAuth(overrides = {}) {
|
|
|
1385
1417
|
// available together.
|
|
1386
1418
|
hooks: {
|
|
1387
1419
|
before: api.createAuthMiddleware(async (ctx) => {
|
|
1388
|
-
var _a2, _b2, _c2, _d2;
|
|
1420
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
1389
1421
|
if (ctx.path === "/sign-in/email" || ctx.path === "/sign-up/email") {
|
|
1390
1422
|
const fingerprint = (_a2 = ctx.headers) == null ? void 0 : _a2.get(DEVICE_FINGERPRINT_HEADER);
|
|
1391
1423
|
const ip = getClientIp(ctx.headers);
|
|
@@ -1419,6 +1451,9 @@ function createAuth(overrides = {}) {
|
|
|
1419
1451
|
}
|
|
1420
1452
|
return;
|
|
1421
1453
|
}
|
|
1454
|
+
if (ctx.request && ((_c2 = ctx.path) == null ? void 0 : _c2.startsWith("/admin/")) && ctx.path !== "/admin/impersonate-user" && ctx.path !== "/admin/stop-impersonating") {
|
|
1455
|
+
throw new api.APIError("FORBIDDEN", { message: "Use the dashboard to manage users." });
|
|
1456
|
+
}
|
|
1422
1457
|
if (ctx.path === "/admin/impersonate-user" && overrides.impersonation === false) {
|
|
1423
1458
|
throw new api.APIError("FORBIDDEN", { message: "Impersonation is turned off." });
|
|
1424
1459
|
}
|
|
@@ -1429,8 +1464,8 @@ function createAuth(overrides = {}) {
|
|
|
1429
1464
|
throw new api.APIError("FORBIDDEN", { message: "Stop impersonating before deleting an account." });
|
|
1430
1465
|
}
|
|
1431
1466
|
if (current2.user.role === "admin") {
|
|
1432
|
-
const [
|
|
1433
|
-
if (
|
|
1467
|
+
const [other] = await db.select({ n: drizzleOrm.sql`1` }).from(users).where(otherActiveAdminExists([current2.user.id])).limit(1);
|
|
1468
|
+
if (!other) {
|
|
1434
1469
|
throw new api.APIError("FORBIDDEN", { message: "You're the only admin. Promote another user to admin first." });
|
|
1435
1470
|
}
|
|
1436
1471
|
}
|
|
@@ -1443,7 +1478,7 @@ function createAuth(overrides = {}) {
|
|
|
1443
1478
|
await log({
|
|
1444
1479
|
userId: current.session.impersonatedBy,
|
|
1445
1480
|
action: "impersonation_stopped",
|
|
1446
|
-
description: `Admin stopped impersonating ${(
|
|
1481
|
+
description: `Admin stopped impersonating ${(_e2 = (_d2 = target[0]) == null ? void 0 : _d2.email) != null ? _e2 : current.session.userId}`,
|
|
1447
1482
|
metadata: { impersonatedUserId: current.session.userId }
|
|
1448
1483
|
});
|
|
1449
1484
|
}
|
|
@@ -1479,8 +1514,6 @@ function createAuth(overrides = {}) {
|
|
|
1479
1514
|
if (failed) {
|
|
1480
1515
|
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
1481
1516
|
await logFailedLogin(ctx, log);
|
|
1482
|
-
} else {
|
|
1483
|
-
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
1484
1517
|
}
|
|
1485
1518
|
})
|
|
1486
1519
|
},
|
|
@@ -1606,7 +1639,7 @@ function unexpectedErrorMessage(error, message = "Something went wrong. Please t
|
|
|
1606
1639
|
return `${message} (ref: ${ref})`;
|
|
1607
1640
|
}
|
|
1608
1641
|
|
|
1609
|
-
// lib/feedback
|
|
1642
|
+
// lib/feedback/route.ts
|
|
1610
1643
|
var feedbackSchema = zod.z.object({
|
|
1611
1644
|
type: zod.z.enum(["bug", "feedback"]),
|
|
1612
1645
|
// Keep in sync with FEEDBACK_MAX_LENGTH in components/dashboard/feedbackDialog.tsx.
|
|
@@ -1615,7 +1648,8 @@ var feedbackSchema = zod.z.object({
|
|
|
1615
1648
|
// The error the user reported from (FeedbackDialog's errorDetails).
|
|
1616
1649
|
error: zod.z.string().max(2e3).optional()
|
|
1617
1650
|
});
|
|
1618
|
-
var
|
|
1651
|
+
var parsedCooldown = Number(process.env.FEEDBACK_COOLDOWN_SECONDS || 30);
|
|
1652
|
+
var COOLDOWN_MS = (Number.isFinite(parsedCooldown) && parsedCooldown >= 0 ? parsedCooldown : 30) * 1e3;
|
|
1619
1653
|
var lastSentAt = /* @__PURE__ */ new Map();
|
|
1620
1654
|
async function POST(request) {
|
|
1621
1655
|
var _a;
|
|
@@ -1624,7 +1658,7 @@ async function POST(request) {
|
|
|
1624
1658
|
if (!discordUrl && !emailTo) {
|
|
1625
1659
|
return server.NextResponse.json({ error: "Feedback is not configured" }, { status: 503 });
|
|
1626
1660
|
}
|
|
1627
|
-
const session = await auth.api.getSession({ headers: await headers.headers() });
|
|
1661
|
+
const session = await auth.api.getSession({ headers: await headers.headers(), query: { disableCookieCache: true } });
|
|
1628
1662
|
if (!(session == null ? void 0 : session.user)) {
|
|
1629
1663
|
return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1630
1664
|
}
|
|
@@ -1639,6 +1673,7 @@ async function POST(request) {
|
|
|
1639
1673
|
{ status: 429 }
|
|
1640
1674
|
);
|
|
1641
1675
|
}
|
|
1676
|
+
for (const [id, at] of lastSentAt) if (now - at >= COOLDOWN_MS) lastSentAt.delete(id);
|
|
1642
1677
|
lastSentAt.set(session.user.id, now);
|
|
1643
1678
|
const { type, message, page } = parsed.data;
|
|
1644
1679
|
const errorDetails = parsed.data.error && (await getSystemSettings()).feedbackAttachErrors ? parsed.data.error : void 0;
|
|
@@ -1711,7 +1746,7 @@ async function testErrorPOST(request) {
|
|
|
1711
1746
|
if (process.env.NODE_ENV !== "development") {
|
|
1712
1747
|
return server.NextResponse.json({ error: "Not found" }, { status: 404 });
|
|
1713
1748
|
}
|
|
1714
|
-
const session = await auth.api.getSession({ headers: await headers.headers() });
|
|
1749
|
+
const session = await auth.api.getSession({ headers: await headers.headers(), query: { disableCookieCache: true } });
|
|
1715
1750
|
if (!(session == null ? void 0 : session.user)) {
|
|
1716
1751
|
return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1717
1752
|
}
|