@xk2800/nextjs-template 0.7.2-beta.1 → 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 -15
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +32 -21
- package/dist/activity/queries.d.ts +32 -21
- package/dist/activity/queries.js +86 -22
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +27 -14
- package/dist/activity/queries.mjs.map +1 -1
- package/dist/admin/queries.d.mts +2 -1
- package/dist/admin/queries.d.ts +2 -1
- package/dist/admin/queries.js +48 -17
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +9 -9
- package/dist/admin/queries.mjs.map +1 -1
- package/dist/api/feedback.js +284 -248
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +14 -12
- package/dist/api/feedback.mjs.map +1 -1
- package/dist/api/marketing.js +302 -266
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +16 -25
- package/dist/api/marketing.mjs.map +1 -1
- package/dist/auth/helpers.d.mts +63 -21
- package/dist/auth/helpers.d.ts +63 -21
- package/dist/auth/helpers.js +314 -267
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +9 -9
- package/dist/auth/index.d.mts +86 -47
- package/dist/auth/index.d.ts +86 -47
- package/dist/auth/index.js +278 -244
- 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-TE5BEAQB.mjs → chunk-3BH6BVBQ.mjs} +17 -7
- package/dist/chunk-3BH6BVBQ.mjs.map +1 -0
- package/dist/chunk-D56ENLSX.mjs +6 -0
- package/dist/chunk-D56ENLSX.mjs.map +1 -0
- package/dist/{chunk-HUEDEAY3.mjs → chunk-DCPVEZS7.mjs} +14 -4
- package/dist/chunk-DCPVEZS7.mjs.map +1 -0
- package/dist/{chunk-NQELV53D.mjs → chunk-DWLMCMXF.mjs} +4 -4
- package/dist/chunk-DWLMCMXF.mjs.map +1 -0
- package/dist/{chunk-653GF7OT.mjs → chunk-EXMUANQ3.mjs} +4 -4
- package/dist/chunk-EXMUANQ3.mjs.map +1 -0
- package/dist/{chunk-EIS4SCQW.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-2BJ3B4FR.mjs → chunk-NJBRKKLK.mjs} +46 -7
- package/dist/chunk-NJBRKKLK.mjs.map +1 -0
- package/dist/{chunk-6OAHCEDJ.mjs → chunk-QDUPSU5O.mjs} +5 -5
- package/dist/chunk-QDUPSU5O.mjs.map +1 -0
- package/dist/{chunk-H3XZTZ5K.mjs → chunk-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-O5EQYHNC.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 -12
- package/dist/db/index.js.map +1 -1
- package/dist/db/index.mjs +3 -3
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +14 -4
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.d.mts +2 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.js +62 -13
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.d.mts +4 -3
- package/dist/marketing/index.d.ts +4 -3
- package/dist/marketing/index.js +14 -4
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{email-template-passkey-change-F5Q2SXHD.mjs → passkey-changed-KEGNTIPE.mjs} +2 -2
- package/dist/passkey-changed-KEGNTIPE.mjs.map +1 -0
- package/dist/{email-template-reset-password-QTCQNXOD.mjs → reset-password-64VQEXBW.mjs} +2 -2
- package/dist/reset-password-64VQEXBW.mjs.map +1 -0
- package/dist/{schema-DzC5zdOq.d.mts → schema-BujGgvAy.d.mts} +35 -2
- package/dist/{schema-DzC5zdOq.d.ts → schema-BujGgvAy.d.ts} +35 -2
- package/dist/sessions/queries.js +61 -12
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/sessions/queries.mjs.map +1 -1
- package/dist/settings/queries.d.mts +11 -2
- package/dist/settings/queries.d.ts +11 -2
- package/dist/settings/queries.js +84 -13
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +41 -21
- package/dist/users/queries.d.ts +41 -21
- package/dist/users/queries.js +117 -23
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +57 -17
- package/dist/users/queries.mjs.map +1 -1
- package/dist/{email-template-verify-email-WZDCCAKK.mjs → verify-email-4KMNGDKN.mjs} +2 -2
- package/dist/verify-email-4KMNGDKN.mjs.map +1 -0
- package/lib/{auth-client.ts → auth/client.ts} +22 -2
- package/lib/push/client.ts +39 -0
- package/lib/security/activity-severity.ts +57 -0
- package/lib/{request-info.ts → utils/request-info.ts} +7 -3
- package/package.json +177 -75
- package/scripts/check-deps.mjs +68 -0
- package/components/dashboard/admin/adminActivityLogsTable.tsx +0 -323
- package/components/dashboard/admin/adminUserStatusCard.tsx +0 -57
- package/components/dashboard/admin/systemSettingsForm.tsx +0 -289
- package/dist/chunk-2BJ3B4FR.mjs.map +0 -1
- package/dist/chunk-653GF7OT.mjs.map +0 -1
- package/dist/chunk-6OAHCEDJ.mjs.map +0 -1
- package/dist/chunk-EIS4SCQW.mjs.map +0 -1
- package/dist/chunk-H3XZTZ5K.mjs.map +0 -1
- package/dist/chunk-HUEDEAY3.mjs.map +0 -1
- package/dist/chunk-K62JYJRR.mjs +0 -30
- package/dist/chunk-K62JYJRR.mjs.map +0 -1
- package/dist/chunk-L242CZ64.mjs.map +0 -1
- package/dist/chunk-NQELV53D.mjs.map +0 -1
- package/dist/chunk-O5EQYHNC.mjs.map +0 -1
- package/dist/chunk-TE5BEAQB.mjs.map +0 -1
- package/dist/email-template-passkey-change-F5Q2SXHD.mjs.map +0 -1
- package/dist/email-template-reset-password-QTCQNXOD.mjs.map +0 -1
- package/dist/email-template-verify-email-WZDCCAKK.mjs.map +0 -1
- /package/components/dashboard/{heartbeat.tsx → common/heartbeat.tsx} +0 -0
- /package/components/email/{email-template-reset-password.tsx → auth/reset-password.tsx} +0 -0
- /package/components/email/{email-template-verify-email.tsx → auth/verify-email.tsx} +0 -0
- /package/components/email/{email-template-welcome.tsx → auth/welcome.tsx} +0 -0
- /package/components/email/{email-template.tsx → layout/base-layout.tsx} +0 -0
- /package/components/email/{email-template-2.tsx → marketing/general-announcement.tsx} +0 -0
- /package/components/email/{email-template-banned.tsx → security/account-banned.tsx} +0 -0
- /package/components/email/{email-template-new-device.tsx → security/new-device-alert.tsx} +0 -0
- /package/components/email/{email-template-passkey-change.tsx → security/passkey-changed.tsx} +0 -0
- /package/lib/{maintenance.ts → config/maintenance.ts} +0 -0
- /package/lib/{cookie-consent.ts → security/cookie-consent.ts} +0 -0
- /package/lib/{cookie-names.ts → security/cookie-names.ts} +0 -0
- /package/lib/{device-fingerprint.ts → security/device-fingerprint.ts} +0 -0
- /package/lib/{formatters.ts → utils/formatters.ts} +0 -0
- /package/lib/{recalculate-columns.ts → utils/recalculate-columns.ts} +0 -0
package/dist/api/marketing.js
CHANGED
|
@@ -49,17 +49,22 @@ var __spreadValues = (a, b) => {
|
|
|
49
49
|
return a;
|
|
50
50
|
};
|
|
51
51
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
52
|
-
var __esm = (fn, res) => function __init() {
|
|
53
|
-
|
|
52
|
+
var __esm = (fn, res, err) => function __init() {
|
|
53
|
+
if (err) throw err[0];
|
|
54
|
+
try {
|
|
55
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
throw err = [e], e;
|
|
58
|
+
}
|
|
54
59
|
};
|
|
55
60
|
var __export = (target, all) => {
|
|
56
61
|
for (var name in all)
|
|
57
62
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
58
63
|
};
|
|
59
64
|
|
|
60
|
-
// components/email/
|
|
61
|
-
var
|
|
62
|
-
__export(
|
|
65
|
+
// components/email/security/passkey-changed.tsx
|
|
66
|
+
var passkey_changed_exports = {};
|
|
67
|
+
__export(passkey_changed_exports, {
|
|
63
68
|
EmailTemplatePasskeyChange: () => EmailTemplatePasskeyChange
|
|
64
69
|
});
|
|
65
70
|
function EmailTemplatePasskeyChange({
|
|
@@ -120,14 +125,14 @@ function EmailTemplatePasskeyChange({
|
|
|
120
125
|
] }) }) }) })
|
|
121
126
|
] });
|
|
122
127
|
}
|
|
123
|
-
var
|
|
124
|
-
"components/email/
|
|
128
|
+
var init_passkey_changed = __esm({
|
|
129
|
+
"components/email/security/passkey-changed.tsx"() {
|
|
125
130
|
}
|
|
126
131
|
});
|
|
127
132
|
|
|
128
|
-
// components/email/
|
|
129
|
-
var
|
|
130
|
-
__export(
|
|
133
|
+
// components/email/auth/reset-password.tsx
|
|
134
|
+
var reset_password_exports = {};
|
|
135
|
+
__export(reset_password_exports, {
|
|
131
136
|
EmailTemplateResetPassword: () => EmailTemplateResetPassword
|
|
132
137
|
});
|
|
133
138
|
function EmailTemplateResetPassword({ firstName, url }) {
|
|
@@ -164,14 +169,14 @@ function EmailTemplateResetPassword({ firstName, url }) {
|
|
|
164
169
|
] }) }) })
|
|
165
170
|
] });
|
|
166
171
|
}
|
|
167
|
-
var
|
|
168
|
-
"components/email/
|
|
172
|
+
var init_reset_password = __esm({
|
|
173
|
+
"components/email/auth/reset-password.tsx"() {
|
|
169
174
|
}
|
|
170
175
|
});
|
|
171
176
|
|
|
172
|
-
// components/email/
|
|
173
|
-
var
|
|
174
|
-
__export(
|
|
177
|
+
// components/email/auth/verify-email.tsx
|
|
178
|
+
var verify_email_exports = {};
|
|
179
|
+
__export(verify_email_exports, {
|
|
175
180
|
EmailTemplateVerifyEmail: () => EmailTemplateVerifyEmail
|
|
176
181
|
});
|
|
177
182
|
function EmailTemplateVerifyEmail({ firstName, url }) {
|
|
@@ -200,8 +205,8 @@ function EmailTemplateVerifyEmail({ firstName, url }) {
|
|
|
200
205
|
] }) }) }) })
|
|
201
206
|
] });
|
|
202
207
|
}
|
|
203
|
-
var
|
|
204
|
-
"components/email/
|
|
208
|
+
var init_verify_email = __esm({
|
|
209
|
+
"components/email/auth/verify-email.tsx"() {
|
|
205
210
|
}
|
|
206
211
|
});
|
|
207
212
|
|
|
@@ -225,7 +230,7 @@ __export(schema_exports, {
|
|
|
225
230
|
verifications: () => verifications
|
|
226
231
|
});
|
|
227
232
|
|
|
228
|
-
// lib/maintenance.ts
|
|
233
|
+
// lib/config/maintenance.ts
|
|
229
234
|
var DEFAULT_MAINTENANCE_EXEMPT_PATHS = [
|
|
230
235
|
"/",
|
|
231
236
|
"/features",
|
|
@@ -292,7 +297,10 @@ var sessions = pgCore.pgTable("session", {
|
|
|
292
297
|
// Set by better-auth's admin plugin while this session is an admin
|
|
293
298
|
// impersonating another user; holds the impersonating admin's user id.
|
|
294
299
|
impersonatedBy: pgCore.text("impersonatedBy")
|
|
295
|
-
})
|
|
300
|
+
}, (table) => [
|
|
301
|
+
// Read by userId on every login (session count), ban/delete and the admin sessions view.
|
|
302
|
+
pgCore.index("session_user_idx").on(table.userId)
|
|
303
|
+
]);
|
|
296
304
|
var accounts = pgCore.pgTable("account", {
|
|
297
305
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
298
306
|
accountId: pgCore.text("accountId").notNull(),
|
|
@@ -341,7 +349,10 @@ var verifications = pgCore.pgTable("verification", {
|
|
|
341
349
|
});
|
|
342
350
|
var activityLogs = pgCore.pgTable("activity_log", {
|
|
343
351
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
344
|
-
|
|
352
|
+
// SET NULL, not cascade: deleting an admin must not erase the audit trail of
|
|
353
|
+
// what they did. actorEmail keeps who it was once the user row is gone.
|
|
354
|
+
userId: pgCore.text("userId").references(() => users.id, { onDelete: "set null" }),
|
|
355
|
+
actorEmail: pgCore.text("actorEmail"),
|
|
345
356
|
action: ActivityActionEnum("action").notNull(),
|
|
346
357
|
description: pgCore.text("description").notNull(),
|
|
347
358
|
ipAddress: pgCore.text("ipAddress"),
|
|
@@ -357,7 +368,11 @@ var activityLogs = pgCore.pgTable("activity_log", {
|
|
|
357
368
|
country: pgCore.text("country"),
|
|
358
369
|
city: pgCore.text("city"),
|
|
359
370
|
createdAt: pgCore.timestamp("createdAt").notNull().defaultNow()
|
|
360
|
-
})
|
|
371
|
+
}, (table) => [
|
|
372
|
+
// Per-user history, and the admin log's newest-first ordering.
|
|
373
|
+
pgCore.index("activity_log_user_created_idx").on(table.userId, table.createdAt),
|
|
374
|
+
pgCore.index("activity_log_created_idx").on(table.createdAt)
|
|
375
|
+
]);
|
|
361
376
|
var deviceFingerprints = pgCore.pgTable("device_fingerprint", {
|
|
362
377
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
363
378
|
userId: pgCore.text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
@@ -472,7 +487,9 @@ var envSchema = zod.z.object({
|
|
|
472
487
|
RESEND_MARKETING_SEGMENT_ID: zod.z.string().default(""),
|
|
473
488
|
// Sender for every transactional email. Must be on a domain verified in
|
|
474
489
|
// your Resend account.
|
|
475
|
-
|
|
490
|
+
// Resend's shared sandbox sender: works without a verified domain but only
|
|
491
|
+
// delivers to your own Resend account email. Set your verified domain for real use.
|
|
492
|
+
EMAIL_FROM: zod.z.string().default("Acme <onboarding@resend.dev>"),
|
|
476
493
|
// Display name for this deployment — shown as the authenticator-app label
|
|
477
494
|
// (2FA issuer) and the passkey relying-party name. Consuming projects set
|
|
478
495
|
// this in their own .env; defaults to the template name.
|
|
@@ -482,6 +499,9 @@ var envSchema = zod.z.object({
|
|
|
482
499
|
// a comma-separated list and sends through Resend (needs RESEND_API_KEY).
|
|
483
500
|
FEEDBACK_DISCORD_WEBHOOK_URL: zod.z.string().default(""),
|
|
484
501
|
FEEDBACK_EMAIL: zod.z.string().default(""),
|
|
502
|
+
// Seconds between feedback messages per user (default 30, 0 = off). Read
|
|
503
|
+
// straight from process.env in lib/feedback/route.ts; listed here for docs.
|
|
504
|
+
FEEDBACK_COOLDOWN_SECONDS: zod.z.string().default("30"),
|
|
485
505
|
// Web Push (example, see lib/push.ts). Generate keys with
|
|
486
506
|
// `bunx web-push generate-vapid-keys`. Blank = the notifications card is hidden.
|
|
487
507
|
// The public key is also read in the browser as NEXT_PUBLIC_VAPID_PUBLIC_KEY.
|
|
@@ -498,7 +518,12 @@ var envSchema = zod.z.object({
|
|
|
498
518
|
DB_DRIVER: zod.z.enum(["pg", "neon"]).default("pg"),
|
|
499
519
|
// Only relevant when DB_DRIVER=pg — whether the target Postgres server has SSL
|
|
500
520
|
// enabled. Self-hosted Postgres (e.g. via Docker/Dokploy) typically does not.
|
|
501
|
-
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true")
|
|
521
|
+
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true"),
|
|
522
|
+
// With DATABASE_SSL=true the server certificate is verified. Set the CA (PEM,
|
|
523
|
+
// "\n" for newlines) for a self-signed or private CA; DATABASE_SSL_INSECURE=true
|
|
524
|
+
// skips verification (encrypts only). Both are read in config/pg-ssl.ts.
|
|
525
|
+
DATABASE_SSL_CA: zod.z.string().default(""),
|
|
526
|
+
DATABASE_SSL_INSECURE: zod.z.string().default("false")
|
|
502
527
|
});
|
|
503
528
|
|
|
504
529
|
// config/env.ts
|
|
@@ -512,24 +537,47 @@ if (!results.success) {
|
|
|
512
537
|
}
|
|
513
538
|
var config = results.data;
|
|
514
539
|
|
|
540
|
+
// config/pg-ssl.ts
|
|
541
|
+
function pgSslOptions() {
|
|
542
|
+
var _a;
|
|
543
|
+
if (process.env.DATABASE_SSL_INSECURE === "true") return { rejectUnauthorized: false };
|
|
544
|
+
const ca = (_a = process.env.DATABASE_SSL_CA) == null ? void 0 : _a.replace(/\\n/g, "\n");
|
|
545
|
+
return __spreadValues({ rejectUnauthorized: true }, ca ? { ca } : {});
|
|
546
|
+
}
|
|
547
|
+
|
|
515
548
|
// server/db/index.ts
|
|
516
549
|
var db;
|
|
517
550
|
if (config.DB_DRIVER === "pg") {
|
|
518
551
|
const pool = new pg.Pool({
|
|
519
552
|
connectionString: config.DATABASE_URL,
|
|
520
|
-
ssl: config.DATABASE_SSL ?
|
|
553
|
+
ssl: config.DATABASE_SSL ? pgSslOptions() : void 0,
|
|
554
|
+
// pg waits forever by default; a hung DB would otherwise freeze every request (proxy reads settings).
|
|
555
|
+
connectionTimeoutMillis: 5e3,
|
|
556
|
+
query_timeout: 15e3
|
|
557
|
+
// roomy enough for the 10k-row exports
|
|
521
558
|
});
|
|
522
559
|
db = nodePostgres.drizzle(pool, {
|
|
523
560
|
schema: schema_exports,
|
|
524
|
-
logger:
|
|
561
|
+
logger: process.env.NODE_ENV === "development"
|
|
525
562
|
});
|
|
526
563
|
console.log("\u{1F7E1} Using PostgreSQL (pg) driver");
|
|
527
|
-
} else if (config.DB_DRIVER === "neon") {
|
|
528
|
-
const sql4 = serverless.neon(config.DATABASE_URL);
|
|
529
|
-
db = neonHttp.drizzle(sql4, { schema: schema_exports, logger: true });
|
|
530
|
-
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
531
564
|
} else {
|
|
532
|
-
|
|
565
|
+
serverless.neonConfig.fetchFunction = (url, init) => fetch(url, __spreadProps(__spreadValues({}, init), { signal: AbortSignal.timeout(15e3) }));
|
|
566
|
+
const sql6 = serverless.neon(config.DATABASE_URL);
|
|
567
|
+
db = neonHttp.drizzle(sql6, { schema: schema_exports, logger: process.env.NODE_ENV === "development" });
|
|
568
|
+
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// node_modules/@better-auth/utils/dist/bytes.mjs
|
|
572
|
+
function toBufferSource(data) {
|
|
573
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
574
|
+
if (!ArrayBuffer.isView(data)) return data;
|
|
575
|
+
if (data.buffer instanceof ArrayBuffer) return data;
|
|
576
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
|
|
577
|
+
}
|
|
578
|
+
function toUint8Array(data) {
|
|
579
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
580
|
+
return new Uint8Array(data);
|
|
533
581
|
}
|
|
534
582
|
|
|
535
583
|
// node_modules/@better-auth/utils/dist/base32.mjs
|
|
@@ -538,9 +586,7 @@ function getAlphabet(hex2) {
|
|
|
538
586
|
}
|
|
539
587
|
function createDecodeMap(alphabet) {
|
|
540
588
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
541
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
542
|
-
decodeMap.set(alphabet[i], i);
|
|
543
|
-
}
|
|
589
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
544
590
|
return decodeMap;
|
|
545
591
|
}
|
|
546
592
|
function base32Encode(data, alphabet, padding) {
|
|
@@ -555,9 +601,7 @@ function base32Encode(data, alphabet, padding) {
|
|
|
555
601
|
result += alphabet[buffer >> shift & 31];
|
|
556
602
|
}
|
|
557
603
|
}
|
|
558
|
-
if (shift > 0)
|
|
559
|
-
result += alphabet[buffer << 5 - shift & 31];
|
|
560
|
-
}
|
|
604
|
+
if (shift > 0) result += alphabet[buffer << 5 - shift & 31];
|
|
561
605
|
if (padding) {
|
|
562
606
|
const padCount = (8 - result.length % 8) % 8;
|
|
563
607
|
result += "=".repeat(padCount);
|
|
@@ -570,12 +614,9 @@ function base32Decode(data, alphabet) {
|
|
|
570
614
|
let buffer = 0;
|
|
571
615
|
let bitsCollected = 0;
|
|
572
616
|
for (const char of data) {
|
|
573
|
-
if (char === "=")
|
|
574
|
-
break;
|
|
617
|
+
if (char === "=") break;
|
|
575
618
|
const value = decodeMap.get(char);
|
|
576
|
-
if (value === void 0) {
|
|
577
|
-
throw new Error(`Invalid Base32 character: ${char}`);
|
|
578
|
-
}
|
|
619
|
+
if (value === void 0) throw new Error(`Invalid Base32 character: ${char}`);
|
|
579
620
|
buffer = buffer << 5 | value;
|
|
580
621
|
bitsCollected += 5;
|
|
581
622
|
while (bitsCollected >= 8) {
|
|
@@ -587,68 +628,34 @@ function base32Decode(data, alphabet) {
|
|
|
587
628
|
}
|
|
588
629
|
var base32 = {
|
|
589
630
|
/**
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
631
|
+
* Encodes data into a Base32 string.
|
|
632
|
+
* @param data - The data to encode (ArrayBuffer, number-based TypedArray, or string).
|
|
633
|
+
* @param options - Encoding options.
|
|
634
|
+
* @returns The Base32 encoded string.
|
|
635
|
+
*/
|
|
595
636
|
encode(data, options = {}) {
|
|
596
637
|
var _a;
|
|
597
638
|
const alphabet = getAlphabet();
|
|
598
|
-
|
|
599
|
-
return base32Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
639
|
+
return base32Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
600
640
|
},
|
|
601
641
|
/**
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
642
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
643
|
+
* @param data - The Base32 encoded string or ArrayBuffer/TypedArray.
|
|
644
|
+
* @returns The decoded Uint8Array.
|
|
645
|
+
*/
|
|
606
646
|
decode(data) {
|
|
607
|
-
if (typeof data !== "string")
|
|
608
|
-
data = new TextDecoder().decode(data);
|
|
609
|
-
}
|
|
647
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
610
648
|
const alphabet = getAlphabet();
|
|
611
649
|
return base32Decode(data, alphabet);
|
|
612
650
|
}
|
|
613
651
|
};
|
|
614
652
|
|
|
615
|
-
// node_modules/@better-auth/utils/dist/
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
}
|
|
622
|
-
if (data.byteLength === 0) {
|
|
623
|
-
return "";
|
|
624
|
-
}
|
|
625
|
-
const buffer = new Uint8Array(data);
|
|
626
|
-
let result = "";
|
|
627
|
-
for (const byte of buffer) {
|
|
628
|
-
result += byte.toString(16).padStart(2, "0");
|
|
629
|
-
}
|
|
630
|
-
return result;
|
|
631
|
-
},
|
|
632
|
-
decode: (data) => {
|
|
633
|
-
if (!data) {
|
|
634
|
-
return "";
|
|
635
|
-
}
|
|
636
|
-
if (typeof data === "string") {
|
|
637
|
-
if (data.length % 2 !== 0) {
|
|
638
|
-
throw new Error("Invalid hexadecimal string");
|
|
639
|
-
}
|
|
640
|
-
if (!new RegExp(`^[${hexadecimal}]+$`).test(data)) {
|
|
641
|
-
throw new Error("Invalid hexadecimal string");
|
|
642
|
-
}
|
|
643
|
-
const result = new Uint8Array(data.length / 2);
|
|
644
|
-
for (let i = 0; i < data.length; i += 2) {
|
|
645
|
-
result[i / 2] = parseInt(data.slice(i, i + 2), 16);
|
|
646
|
-
}
|
|
647
|
-
return new TextDecoder().decode(result);
|
|
648
|
-
}
|
|
649
|
-
return new TextDecoder().decode(data);
|
|
650
|
-
}
|
|
651
|
-
};
|
|
653
|
+
// node_modules/@better-auth/utils/dist/index.mjs
|
|
654
|
+
function getWebcryptoSubtle() {
|
|
655
|
+
const cr = typeof globalThis !== "undefined" && globalThis.crypto;
|
|
656
|
+
if (cr && typeof cr.subtle === "object" && cr.subtle != null) return cr.subtle;
|
|
657
|
+
throw new Error("crypto.subtle must be defined");
|
|
658
|
+
}
|
|
652
659
|
|
|
653
660
|
// node_modules/@better-auth/utils/dist/base64.mjs
|
|
654
661
|
function getAlphabet2(urlSafe) {
|
|
@@ -666,9 +673,7 @@ function base64Encode(data, alphabet, padding) {
|
|
|
666
673
|
result += alphabet[buffer >> shift & 63];
|
|
667
674
|
}
|
|
668
675
|
}
|
|
669
|
-
if (shift > 0)
|
|
670
|
-
result += alphabet[buffer << 6 - shift & 63];
|
|
671
|
-
}
|
|
676
|
+
if (shift > 0) result += alphabet[buffer << 6 - shift & 63];
|
|
672
677
|
if (padding) {
|
|
673
678
|
const padCount = (4 - result.length % 4) % 4;
|
|
674
679
|
result += "=".repeat(padCount);
|
|
@@ -677,19 +682,14 @@ function base64Encode(data, alphabet, padding) {
|
|
|
677
682
|
}
|
|
678
683
|
function base64Decode(data, alphabet) {
|
|
679
684
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
680
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
681
|
-
decodeMap.set(alphabet[i], i);
|
|
682
|
-
}
|
|
685
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
683
686
|
const result = [];
|
|
684
687
|
let buffer = 0;
|
|
685
688
|
let bitsCollected = 0;
|
|
686
689
|
for (const char of data) {
|
|
687
|
-
if (char === "=")
|
|
688
|
-
break;
|
|
690
|
+
if (char === "=") break;
|
|
689
691
|
const value = decodeMap.get(char);
|
|
690
|
-
if (value === void 0) {
|
|
691
|
-
throw new Error(`Invalid Base64 character: ${char}`);
|
|
692
|
-
}
|
|
692
|
+
if (value === void 0) throw new Error(`Invalid Base64 character: ${char}`);
|
|
693
693
|
buffer = buffer << 6 | value;
|
|
694
694
|
bitsCollected += 6;
|
|
695
695
|
if (bitsCollected >= 8) {
|
|
@@ -703,15 +703,11 @@ var base64 = {
|
|
|
703
703
|
encode(data, options = {}) {
|
|
704
704
|
var _a;
|
|
705
705
|
const alphabet = getAlphabet2(false);
|
|
706
|
-
|
|
707
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
706
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
708
707
|
},
|
|
709
708
|
decode(data) {
|
|
710
|
-
if (typeof data !== "string")
|
|
711
|
-
|
|
712
|
-
}
|
|
713
|
-
const urlSafe = data.includes("-") || data.includes("_");
|
|
714
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
709
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
710
|
+
const alphabet = getAlphabet2(data.includes("-") || data.includes("_"));
|
|
715
711
|
return base64Decode(data, alphabet);
|
|
716
712
|
}
|
|
717
713
|
};
|
|
@@ -719,152 +715,142 @@ var base64Url = {
|
|
|
719
715
|
encode(data, options = {}) {
|
|
720
716
|
var _a;
|
|
721
717
|
const alphabet = getAlphabet2(true);
|
|
722
|
-
|
|
723
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
718
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
724
719
|
},
|
|
725
720
|
decode(data) {
|
|
726
|
-
|
|
727
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
728
|
-
return base64Decode(data, alphabet);
|
|
721
|
+
return base64Decode(data, getAlphabet2(data.includes("-") || data.includes("_")));
|
|
729
722
|
}
|
|
730
723
|
};
|
|
731
724
|
|
|
732
|
-
// node_modules/@
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
725
|
+
// node_modules/@noble/hashes/utils.js
|
|
726
|
+
var hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
727
|
+
// @ts-ignore
|
|
728
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
729
|
+
))();
|
|
730
|
+
function asciiToBase16(ch) {
|
|
731
|
+
return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
|
|
732
|
+
}
|
|
733
|
+
function hexToBytes(hex2) {
|
|
734
|
+
if (typeof hex2 !== "string")
|
|
735
|
+
throw new TypeError("hex string expected, got " + typeof hex2);
|
|
736
|
+
if (hasHexBuiltin) {
|
|
737
|
+
try {
|
|
738
|
+
return Uint8Array.fromHex(hex2);
|
|
739
|
+
} catch (error) {
|
|
740
|
+
if (error instanceof SyntaxError)
|
|
741
|
+
throw new RangeError(error.message);
|
|
742
|
+
throw error;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
const hl = hex2.length;
|
|
746
|
+
const al = hl / 2;
|
|
747
|
+
if (hl % 2)
|
|
748
|
+
throw new RangeError("hex string expected, got unpadded hex of length " + hl);
|
|
749
|
+
const array = new Uint8Array(al);
|
|
750
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
751
|
+
const n1 = asciiToBase16(hex2.charCodeAt(hi));
|
|
752
|
+
const n2 = asciiToBase16(hex2.charCodeAt(hi + 1));
|
|
753
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
754
|
+
const char = hex2[hi] + hex2[hi + 1];
|
|
755
|
+
throw new RangeError('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
756
|
+
}
|
|
757
|
+
array[ai] = n1 * 16 + n2;
|
|
758
|
+
}
|
|
759
|
+
return array;
|
|
738
760
|
}
|
|
739
761
|
|
|
762
|
+
// node_modules/@better-auth/utils/dist/hex.mjs
|
|
763
|
+
var toBytes = (data) => hexToBytes(data);
|
|
764
|
+
var hex = {
|
|
765
|
+
encode: (data) => {
|
|
766
|
+
const buffer = toUint8Array(data);
|
|
767
|
+
if (buffer.byteLength === 0) return "";
|
|
768
|
+
let result = "";
|
|
769
|
+
for (const byte of buffer) result += byte.toString(16).padStart(2, "0");
|
|
770
|
+
return result;
|
|
771
|
+
},
|
|
772
|
+
decode: (data) => {
|
|
773
|
+
if (!data) return "";
|
|
774
|
+
if (typeof data === "string") return new TextDecoder().decode(toBytes(data));
|
|
775
|
+
return new TextDecoder().decode(data);
|
|
776
|
+
},
|
|
777
|
+
toBytes
|
|
778
|
+
};
|
|
779
|
+
|
|
740
780
|
// node_modules/@better-auth/utils/dist/hmac.mjs
|
|
741
781
|
var createHMAC = (algorithm = "SHA-256", encoding = "none") => {
|
|
742
|
-
const
|
|
782
|
+
const hmac2 = {
|
|
743
783
|
importKey: async (key, keyUsage) => {
|
|
744
|
-
return getWebcryptoSubtle().importKey(
|
|
745
|
-
"
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
false,
|
|
749
|
-
[keyUsage]
|
|
750
|
-
);
|
|
784
|
+
return getWebcryptoSubtle().importKey("raw", toBufferSource(key), {
|
|
785
|
+
name: "HMAC",
|
|
786
|
+
hash: { name: algorithm }
|
|
787
|
+
}, false, [keyUsage]);
|
|
751
788
|
},
|
|
752
789
|
sign: async (hmacKey, data) => {
|
|
753
|
-
if (typeof hmacKey === "string")
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
hmacKey,
|
|
759
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
760
|
-
);
|
|
761
|
-
if (encoding === "hex") {
|
|
762
|
-
return hex.encode(signature);
|
|
763
|
-
}
|
|
764
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
765
|
-
return base64Url.encode(signature, {
|
|
766
|
-
padding: encoding !== "base64urlnopad"
|
|
767
|
-
});
|
|
768
|
-
}
|
|
790
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "sign");
|
|
791
|
+
const signature = await getWebcryptoSubtle().sign("HMAC", hmacKey, toBufferSource(data));
|
|
792
|
+
if (encoding === "hex") return hex.encode(signature);
|
|
793
|
+
if (encoding === "base64") return base64.encode(signature);
|
|
794
|
+
if (encoding === "base64url" || encoding === "base64urlnopad") return base64Url.encode(signature, { padding: encoding !== "base64urlnopad" });
|
|
769
795
|
return signature;
|
|
770
796
|
},
|
|
771
797
|
verify: async (hmacKey, data, signature) => {
|
|
772
|
-
if (typeof hmacKey === "string")
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
signature = hex.decode(signature);
|
|
777
|
-
}
|
|
778
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
779
|
-
signature = await base64.decode(signature);
|
|
780
|
-
}
|
|
781
|
-
return getWebcryptoSubtle().verify(
|
|
782
|
-
"HMAC",
|
|
783
|
-
hmacKey,
|
|
784
|
-
typeof signature === "string" ? new TextEncoder().encode(signature) : signature,
|
|
785
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
786
|
-
);
|
|
798
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "verify");
|
|
799
|
+
if (encoding === "hex") signature = typeof signature === "string" ? hex.toBytes(signature) : signature;
|
|
800
|
+
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") signature = await base64.decode(signature);
|
|
801
|
+
return getWebcryptoSubtle().verify("HMAC", hmacKey, toBufferSource(signature), toBufferSource(data));
|
|
787
802
|
}
|
|
788
803
|
};
|
|
789
|
-
return
|
|
804
|
+
return hmac2;
|
|
790
805
|
};
|
|
791
806
|
|
|
792
807
|
// node_modules/@better-auth/utils/dist/otp.mjs
|
|
793
808
|
var defaultPeriod = 30;
|
|
794
809
|
var defaultDigits = 6;
|
|
810
|
+
var hmac = createHMAC("SHA-1");
|
|
795
811
|
function constantTimeEqualOTP(input, expected) {
|
|
796
812
|
let difference = input.length ^ expected.length;
|
|
797
|
-
for (let i = 0; i < expected.length; i++)
|
|
798
|
-
difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
799
|
-
}
|
|
813
|
+
for (let i = 0; i < expected.length; i++) difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
800
814
|
return difference === 0;
|
|
801
815
|
}
|
|
802
|
-
async function generateHOTP(
|
|
803
|
-
counter,
|
|
804
|
-
digits,
|
|
805
|
-
hash = "SHA-1"
|
|
806
|
-
}) {
|
|
816
|
+
async function generateHOTP(key, { counter, digits }) {
|
|
807
817
|
const _digits = digits != null ? digits : defaultDigits;
|
|
808
|
-
if (_digits < 1 || _digits > 8)
|
|
809
|
-
|
|
810
|
-
}
|
|
811
|
-
const buffer = new ArrayBuffer(8);
|
|
818
|
+
if (_digits < 1 || _digits > 8) throw new TypeError("Digits must be between 1 and 8");
|
|
819
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
812
820
|
new DataView(buffer).setBigUint64(0, BigInt(counter), false);
|
|
813
821
|
const bytes = new Uint8Array(buffer);
|
|
814
|
-
const
|
|
822
|
+
const signature = await hmac.sign(key, bytes);
|
|
823
|
+
const hmacResult = new Uint8Array(signature);
|
|
815
824
|
const offset = hmacResult[hmacResult.length - 1] & 15;
|
|
816
|
-
|
|
817
|
-
const otp = truncated % 10 ** _digits;
|
|
818
|
-
return otp.toString().padStart(_digits, "0");
|
|
825
|
+
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");
|
|
819
826
|
}
|
|
820
|
-
async function generateTOTP(
|
|
827
|
+
async function generateTOTP(key, options) {
|
|
821
828
|
var _a, _b;
|
|
822
829
|
const digits = (_a = options == null ? void 0 : options.digits) != null ? _a : defaultDigits;
|
|
823
|
-
const
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
830
|
+
const milliseconds = ((_b = options == null ? void 0 : options.period) != null ? _b : defaultPeriod) * 1e3;
|
|
831
|
+
return await generateHOTP(key, {
|
|
832
|
+
counter: Math.floor(Date.now() / milliseconds),
|
|
833
|
+
digits
|
|
834
|
+
});
|
|
827
835
|
}
|
|
828
|
-
async function verifyTOTP(otp, {
|
|
829
|
-
window = 1,
|
|
830
|
-
digits = defaultDigits,
|
|
831
|
-
secret,
|
|
832
|
-
period = defaultPeriod
|
|
833
|
-
}) {
|
|
836
|
+
async function verifyTOTP(otp, { window = 1, digits = defaultDigits, key, period = defaultPeriod }) {
|
|
834
837
|
const milliseconds = period * 1e3;
|
|
835
838
|
const counter = Math.floor(Date.now() / milliseconds);
|
|
836
839
|
let matched = false;
|
|
837
|
-
for (let i = -window; i <= window; i++) {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
});
|
|
842
|
-
matched = constantTimeEqualOTP(otp, generatedOTP) || matched;
|
|
843
|
-
}
|
|
840
|
+
for (let i = -window; i <= window; i++) matched = constantTimeEqualOTP(otp, await generateHOTP(key, {
|
|
841
|
+
counter: counter + i,
|
|
842
|
+
digits
|
|
843
|
+
})) || matched;
|
|
844
844
|
return matched;
|
|
845
845
|
}
|
|
846
|
-
function generateQRCode({
|
|
847
|
-
issuer
|
|
848
|
-
account,
|
|
849
|
-
secret,
|
|
850
|
-
digits = defaultDigits,
|
|
851
|
-
period = defaultPeriod
|
|
852
|
-
}) {
|
|
853
|
-
const encodedIssuer = encodeURIComponent(issuer);
|
|
854
|
-
const encodedAccountName = encodeURIComponent(account);
|
|
855
|
-
const baseURI = `otpauth://totp/${encodedIssuer}:${encodedAccountName}`;
|
|
846
|
+
function generateQRCode({ issuer, account, secret, digits = defaultDigits, period = defaultPeriod }) {
|
|
847
|
+
const baseURI = `otpauth://totp/${encodeURIComponent(issuer)}:${encodeURIComponent(account)}`;
|
|
856
848
|
const params = new URLSearchParams({
|
|
857
|
-
secret: base32.encode(secret, {
|
|
858
|
-
padding: false
|
|
859
|
-
}),
|
|
849
|
+
secret: base32.encode(secret, { padding: false }),
|
|
860
850
|
issuer
|
|
861
851
|
});
|
|
862
|
-
if (digits !== void 0)
|
|
863
|
-
|
|
864
|
-
}
|
|
865
|
-
if (period !== void 0) {
|
|
866
|
-
params.set("period", period.toString());
|
|
867
|
-
}
|
|
852
|
+
if (digits !== void 0) params.set("digits", digits.toString());
|
|
853
|
+
if (period !== void 0) params.set("period", period.toString());
|
|
868
854
|
return `${baseURI}?${params.toString()}`;
|
|
869
855
|
}
|
|
870
856
|
var createOTP = (secret, opts) => {
|
|
@@ -872,14 +858,38 @@ var createOTP = (secret, opts) => {
|
|
|
872
858
|
const digits = (_a = void 0 ) != null ? _a : defaultDigits;
|
|
873
859
|
const period = (_b = void 0 ) != null ? _b : defaultPeriod;
|
|
874
860
|
return {
|
|
875
|
-
hotp: (counter) =>
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
861
|
+
hotp: async (counter) => {
|
|
862
|
+
return generateHOTP(await hmac.importKey(secret, "sign"), {
|
|
863
|
+
counter,
|
|
864
|
+
digits
|
|
865
|
+
});
|
|
866
|
+
},
|
|
867
|
+
totp: async () => {
|
|
868
|
+
return generateTOTP(await hmac.importKey(secret, "sign"), {
|
|
869
|
+
digits,
|
|
870
|
+
period
|
|
871
|
+
});
|
|
872
|
+
},
|
|
873
|
+
verify: async (otp, options) => {
|
|
874
|
+
return verifyTOTP(otp, __spreadValues({
|
|
875
|
+
key: await hmac.importKey(secret, "sign"),
|
|
876
|
+
digits,
|
|
877
|
+
period
|
|
878
|
+
}, options));
|
|
879
|
+
},
|
|
880
|
+
url: (issuer, account) => {
|
|
881
|
+
return generateQRCode({
|
|
882
|
+
issuer,
|
|
883
|
+
account,
|
|
884
|
+
secret,
|
|
885
|
+
digits,
|
|
886
|
+
period
|
|
887
|
+
});
|
|
888
|
+
}
|
|
879
889
|
};
|
|
880
890
|
};
|
|
881
891
|
|
|
882
|
-
// lib/two-factor.ts
|
|
892
|
+
// lib/auth/two-factor.ts
|
|
883
893
|
var CHALLENGED_PATHS = ["/callback/:id", "/one-tap/callback"];
|
|
884
894
|
var CODE_REQUIRED_PATHS = ["/two-factor/disable", "/two-factor/generate-backup-codes"];
|
|
885
895
|
function twoFactorPlugins(baseURL, { issuer, passwordless = false, challengeAfterOAuth = false }) {
|
|
@@ -952,6 +962,8 @@ async function logActivity({
|
|
|
952
962
|
try {
|
|
953
963
|
await db.insert(activityLogs).values({
|
|
954
964
|
userId,
|
|
965
|
+
// Snapshot the email at write time; survives deletion of the user row.
|
|
966
|
+
actorEmail: drizzleOrm.sql`(select "email" from "user" where "id" = ${userId})`,
|
|
955
967
|
action,
|
|
956
968
|
description,
|
|
957
969
|
ipAddress: ipAddress || null,
|
|
@@ -972,7 +984,7 @@ var countryNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
|
972
984
|
function getClientIp(headers3) {
|
|
973
985
|
var _a;
|
|
974
986
|
const forwardedFor = headers3 == null ? void 0 : headers3.get("x-forwarded-for");
|
|
975
|
-
if (forwardedFor) return forwardedFor.split(",")
|
|
987
|
+
if (forwardedFor) return forwardedFor.split(",").at(-1).trim();
|
|
976
988
|
return (_a = headers3 == null ? void 0 : headers3.get("x-real-ip")) != null ? _a : null;
|
|
977
989
|
}
|
|
978
990
|
function parseUserAgent(userAgent) {
|
|
@@ -1011,11 +1023,21 @@ function formatLocation({ country, city }) {
|
|
|
1011
1023
|
return [city, country].filter(Boolean).join(", ");
|
|
1012
1024
|
}
|
|
1013
1025
|
|
|
1014
|
-
// lib/cookie-names.ts
|
|
1026
|
+
// lib/security/cookie-names.ts
|
|
1015
1027
|
var LOGIN_REFERRER_COOKIE = "login_referrer";
|
|
1016
1028
|
var DEVICE_FINGERPRINT_HEADER = "x-device-fingerprint";
|
|
1017
1029
|
|
|
1018
|
-
// lib/auth-
|
|
1030
|
+
// lib/auth/base-url.ts
|
|
1031
|
+
function getBaseUrl() {
|
|
1032
|
+
const url = process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
|
|
1033
|
+
return url.replace(/\/+$/, "");
|
|
1034
|
+
}
|
|
1035
|
+
function otherActiveAdminExists(excludeIds) {
|
|
1036
|
+
const ids = drizzleOrm.sql.join(excludeIds.map((id) => drizzleOrm.sql`${id}`), drizzleOrm.sql`, `);
|
|
1037
|
+
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`;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// lib/auth/throttle-limits.ts
|
|
1019
1041
|
var WINDOW_MS = 15 * 60 * 1e3;
|
|
1020
1042
|
var MAX = 10;
|
|
1021
1043
|
var MAX_IP = MAX * 3;
|
|
@@ -1026,7 +1048,7 @@ function isOverLimit(row, now, max = MAX) {
|
|
|
1026
1048
|
return row.count >= max;
|
|
1027
1049
|
}
|
|
1028
1050
|
|
|
1029
|
-
// lib/auth
|
|
1051
|
+
// lib/auth/throttle.ts
|
|
1030
1052
|
async function isDeviceThrottled(fingerprint, max) {
|
|
1031
1053
|
try {
|
|
1032
1054
|
const [row] = await db.select({ count: authThrottle.count, windowStart: authThrottle.windowStart }).from(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint)).limit(1);
|
|
@@ -1050,8 +1072,10 @@ async function recordDeviceAttempt(fingerprint, meta) {
|
|
|
1050
1072
|
await db.insert(authThrottle).values(__spreadValues({ fingerprint, count: 1, windowStart: now }, seen)).onConflictDoUpdate({
|
|
1051
1073
|
target: authThrottle.fingerprint,
|
|
1052
1074
|
set: __spreadValues({
|
|
1053
|
-
|
|
1054
|
-
|
|
1075
|
+
// ISO strings, not Dates: pg sends a raw Date as server-local time, which a
|
|
1076
|
+
// tz-less `timestamp` column (stored as UTC) misreads on any non-UTC host.
|
|
1077
|
+
count: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then 1 else ${authThrottle.count} + 1 end`,
|
|
1078
|
+
windowStart: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then ${now.toISOString()} else ${authThrottle.windowStart} end`
|
|
1055
1079
|
}, seen)
|
|
1056
1080
|
});
|
|
1057
1081
|
} catch (error) {
|
|
@@ -1070,15 +1094,9 @@ async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
|
1070
1094
|
console.error("auth-throttle prune failed", error);
|
|
1071
1095
|
}
|
|
1072
1096
|
}
|
|
1073
|
-
async function clearDeviceThrottle(fingerprint) {
|
|
1074
|
-
try {
|
|
1075
|
-
await db.delete(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint));
|
|
1076
|
-
} catch (error) {
|
|
1077
|
-
console.error("auth-throttle clear failed", error);
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
1097
|
var SETTINGS_ROW_ID = "default";
|
|
1081
1098
|
var CACHE_TTL_MS = 1e4;
|
|
1099
|
+
var FAILURE_CACHE_TTL_MS = 5e3;
|
|
1082
1100
|
var cached = null;
|
|
1083
1101
|
function fallbackSettings() {
|
|
1084
1102
|
return {
|
|
@@ -1121,7 +1139,9 @@ async function getSystemSettings() {
|
|
|
1121
1139
|
return value;
|
|
1122
1140
|
} catch (error) {
|
|
1123
1141
|
console.error("Failed to load system settings, failing open:", error);
|
|
1124
|
-
|
|
1142
|
+
const value = fallbackSettings();
|
|
1143
|
+
cached = { value, expiresAt: now + FAILURE_CACHE_TTL_MS };
|
|
1144
|
+
return value;
|
|
1125
1145
|
}
|
|
1126
1146
|
}
|
|
1127
1147
|
async function getEffectiveAuthFlags() {
|
|
@@ -1186,7 +1206,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1186
1206
|
userAgent: (_b = (_a = ctx.headers) == null ? void 0 : _a.get("user-agent")) != null ? _b : null
|
|
1187
1207
|
});
|
|
1188
1208
|
if (!config.RESEND_API_KEY) return;
|
|
1189
|
-
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (
|
|
1209
|
+
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (init_passkey_changed(), passkey_changed_exports));
|
|
1190
1210
|
await (await getResend()).emails.send({
|
|
1191
1211
|
from: EMAIL_FROM,
|
|
1192
1212
|
to: [user.email],
|
|
@@ -1198,7 +1218,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1198
1218
|
location: formatLocation(lookupGeoLocation(ip)),
|
|
1199
1219
|
ipAddress: ip || "Unknown",
|
|
1200
1220
|
when: (/* @__PURE__ */ new Date()).toUTCString(),
|
|
1201
|
-
manageUrl: `${
|
|
1221
|
+
manageUrl: `${getBaseUrl()}/dashboard/settings`
|
|
1202
1222
|
})
|
|
1203
1223
|
});
|
|
1204
1224
|
} catch (error) {
|
|
@@ -1249,6 +1269,15 @@ async function packageSessionCreated(log, ...[session, context]) {
|
|
|
1249
1269
|
console.error("Failed to log login activity", error);
|
|
1250
1270
|
}
|
|
1251
1271
|
}
|
|
1272
|
+
async function promoteFirstAdmin(user) {
|
|
1273
|
+
var _a;
|
|
1274
|
+
const adminEmail = (_a = process.env.ADMIN_EMAIL) == null ? void 0 : _a.trim().toLowerCase();
|
|
1275
|
+
if (!adminEmail || !user.emailVerified || user.email.toLowerCase() !== adminEmail) return;
|
|
1276
|
+
const [existing] = await db.select({ id: users.id }).from(users).where(drizzleOrm.eq(users.role, "admin")).limit(1);
|
|
1277
|
+
if (existing) return;
|
|
1278
|
+
await db.update(users).set({ role: "admin" }).where(drizzleOrm.eq(users.id, user.id));
|
|
1279
|
+
user.role = "admin";
|
|
1280
|
+
}
|
|
1252
1281
|
function createAuth(overrides = {}) {
|
|
1253
1282
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1254
1283
|
const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
|
|
@@ -1264,7 +1293,7 @@ function createAuth(overrides = {}) {
|
|
|
1264
1293
|
"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: {...} })."
|
|
1265
1294
|
);
|
|
1266
1295
|
}
|
|
1267
|
-
const baseURL =
|
|
1296
|
+
const baseURL = getBaseUrl();
|
|
1268
1297
|
const log = (_a = overrides.logActivity) != null ? _a : logActivity;
|
|
1269
1298
|
const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
|
|
1270
1299
|
issuer: config.APP_NAME,
|
|
@@ -1312,7 +1341,7 @@ function createAuth(overrides = {}) {
|
|
|
1312
1341
|
// callbackURL) — see app/(auth)/forgot-password and reset-password for
|
|
1313
1342
|
// the pages this points at.
|
|
1314
1343
|
async sendResetPassword({ user, url }) {
|
|
1315
|
-
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (
|
|
1344
|
+
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (init_reset_password(), reset_password_exports));
|
|
1316
1345
|
await (await getResend()).emails.send({
|
|
1317
1346
|
from: EMAIL_FROM,
|
|
1318
1347
|
to: [user.email],
|
|
@@ -1328,8 +1357,11 @@ function createAuth(overrides = {}) {
|
|
|
1328
1357
|
// callback that flips users.emailVerified on click.
|
|
1329
1358
|
emailVerification: {
|
|
1330
1359
|
autoSignInAfterVerification: true,
|
|
1360
|
+
async afterEmailVerification(user) {
|
|
1361
|
+
await promoteFirstAdmin(user);
|
|
1362
|
+
},
|
|
1331
1363
|
async sendVerificationEmail({ user, url }) {
|
|
1332
|
-
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (
|
|
1364
|
+
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (init_verify_email(), verify_email_exports));
|
|
1333
1365
|
await (await getResend()).emails.send({
|
|
1334
1366
|
from: EMAIL_FROM,
|
|
1335
1367
|
to: [user.email],
|
|
@@ -1371,6 +1403,7 @@ function createAuth(overrides = {}) {
|
|
|
1371
1403
|
create: {
|
|
1372
1404
|
async after(user, context) {
|
|
1373
1405
|
var _a2, _b2, _c2, _d2;
|
|
1406
|
+
await promoteFirstAdmin(user);
|
|
1374
1407
|
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));
|
|
1375
1408
|
}
|
|
1376
1409
|
}
|
|
@@ -1394,7 +1427,7 @@ function createAuth(overrides = {}) {
|
|
|
1394
1427
|
// available together.
|
|
1395
1428
|
hooks: {
|
|
1396
1429
|
before: api.createAuthMiddleware(async (ctx) => {
|
|
1397
|
-
var _a2, _b2, _c2, _d2;
|
|
1430
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
1398
1431
|
if (ctx.path === "/sign-in/email" || ctx.path === "/sign-up/email") {
|
|
1399
1432
|
const fingerprint = (_a2 = ctx.headers) == null ? void 0 : _a2.get(DEVICE_FINGERPRINT_HEADER);
|
|
1400
1433
|
const ip = getClientIp(ctx.headers);
|
|
@@ -1428,6 +1461,9 @@ function createAuth(overrides = {}) {
|
|
|
1428
1461
|
}
|
|
1429
1462
|
return;
|
|
1430
1463
|
}
|
|
1464
|
+
if (ctx.request && ((_c2 = ctx.path) == null ? void 0 : _c2.startsWith("/admin/")) && ctx.path !== "/admin/impersonate-user" && ctx.path !== "/admin/stop-impersonating") {
|
|
1465
|
+
throw new api.APIError("FORBIDDEN", { message: "Use the dashboard to manage users." });
|
|
1466
|
+
}
|
|
1431
1467
|
if (ctx.path === "/admin/impersonate-user" && overrides.impersonation === false) {
|
|
1432
1468
|
throw new api.APIError("FORBIDDEN", { message: "Impersonation is turned off." });
|
|
1433
1469
|
}
|
|
@@ -1438,8 +1474,8 @@ function createAuth(overrides = {}) {
|
|
|
1438
1474
|
throw new api.APIError("FORBIDDEN", { message: "Stop impersonating before deleting an account." });
|
|
1439
1475
|
}
|
|
1440
1476
|
if (current2.user.role === "admin") {
|
|
1441
|
-
const [
|
|
1442
|
-
if (
|
|
1477
|
+
const [other] = await db.select({ n: drizzleOrm.sql`1` }).from(users).where(otherActiveAdminExists([current2.user.id])).limit(1);
|
|
1478
|
+
if (!other) {
|
|
1443
1479
|
throw new api.APIError("FORBIDDEN", { message: "You're the only admin. Promote another user to admin first." });
|
|
1444
1480
|
}
|
|
1445
1481
|
}
|
|
@@ -1452,7 +1488,7 @@ function createAuth(overrides = {}) {
|
|
|
1452
1488
|
await log({
|
|
1453
1489
|
userId: current.session.impersonatedBy,
|
|
1454
1490
|
action: "impersonation_stopped",
|
|
1455
|
-
description: `Admin stopped impersonating ${(
|
|
1491
|
+
description: `Admin stopped impersonating ${(_e2 = (_d2 = target[0]) == null ? void 0 : _d2.email) != null ? _e2 : current.session.userId}`,
|
|
1456
1492
|
metadata: { impersonatedUserId: current.session.userId }
|
|
1457
1493
|
});
|
|
1458
1494
|
}
|
|
@@ -1488,8 +1524,6 @@ function createAuth(overrides = {}) {
|
|
|
1488
1524
|
if (failed) {
|
|
1489
1525
|
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
1490
1526
|
await logFailedLogin(ctx, log);
|
|
1491
|
-
} else {
|
|
1492
|
-
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
1493
1527
|
}
|
|
1494
1528
|
})
|
|
1495
1529
|
},
|
|
@@ -1570,14 +1604,25 @@ var auth = new Proxy({}, {
|
|
|
1570
1604
|
return Reflect.getOwnPropertyDescriptor(getDefaultAuth(), prop);
|
|
1571
1605
|
}
|
|
1572
1606
|
});
|
|
1607
|
+
|
|
1608
|
+
// lib/auth/pure.ts
|
|
1609
|
+
function hasRole(userRole, requiredRole) {
|
|
1610
|
+
if (!userRole) return false;
|
|
1611
|
+
{
|
|
1612
|
+
return userRole === "admin";
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
// lib/auth/helpers.ts
|
|
1573
1617
|
var getCurrentSession = react.cache(async () => {
|
|
1574
1618
|
const session = await auth.api.getSession({
|
|
1575
|
-
headers: await headers.headers()
|
|
1619
|
+
headers: await headers.headers(),
|
|
1620
|
+
query: { disableCookieCache: true }
|
|
1576
1621
|
});
|
|
1577
1622
|
return session;
|
|
1578
1623
|
});
|
|
1579
1624
|
react.cache(async () => {
|
|
1580
|
-
var _a;
|
|
1625
|
+
var _a, _b, _c;
|
|
1581
1626
|
const session = await getCurrentSession();
|
|
1582
1627
|
if (!(session == null ? void 0 : session.user)) {
|
|
1583
1628
|
navigation.redirect("/login");
|
|
@@ -1589,13 +1634,13 @@ react.cache(async () => {
|
|
|
1589
1634
|
});
|
|
1590
1635
|
navigation.redirect("/login?error=account_banned");
|
|
1591
1636
|
}
|
|
1592
|
-
return session;
|
|
1637
|
+
return __spreadProps(__spreadValues({}, session), { user: __spreadProps(__spreadValues({}, session.user), { role: (_c = (_b = user[0]) == null ? void 0 : _b.role) != null ? _c : session.user.role }) });
|
|
1593
1638
|
});
|
|
1594
|
-
function
|
|
1595
|
-
|
|
1596
|
-
{
|
|
1597
|
-
|
|
1598
|
-
|
|
1639
|
+
async function requireAdminApi() {
|
|
1640
|
+
const session = await auth.api.getSession({ headers: await headers.headers(), query: { disableCookieCache: true } });
|
|
1641
|
+
if (!(session == null ? void 0 : session.user)) return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1642
|
+
if (!hasRole(session.user.role)) return server.NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
1643
|
+
return session;
|
|
1599
1644
|
}
|
|
1600
1645
|
var MARKETING_SEGMENT_ID = config.RESEND_MARKETING_SEGMENT_ID;
|
|
1601
1646
|
async function setSubscribed(email, name, subscribed) {
|
|
@@ -1619,7 +1664,7 @@ async function setSubscribed(email, name, subscribed) {
|
|
|
1619
1664
|
}
|
|
1620
1665
|
}
|
|
1621
1666
|
|
|
1622
|
-
// lib/marketing-email.ts
|
|
1667
|
+
// lib/email/marketing-email.ts
|
|
1623
1668
|
var UNSUBSCRIBE_PLACEHOLDER = "{{{RESEND_UNSUBSCRIBE_URL}}}";
|
|
1624
1669
|
var escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1625
1670
|
function textToBroadcastHtml(text2) {
|
|
@@ -1669,19 +1714,10 @@ function unexpectedErrorMessage(error, message = "Something went wrong. Please t
|
|
|
1669
1714
|
return `${message} (ref: ${ref})`;
|
|
1670
1715
|
}
|
|
1671
1716
|
|
|
1672
|
-
// lib/marketing
|
|
1673
|
-
async function getSession() {
|
|
1674
|
-
return auth.api.getSession({ headers: await headers.headers() });
|
|
1675
|
-
}
|
|
1717
|
+
// lib/marketing/route.ts
|
|
1676
1718
|
async function requireAdmin() {
|
|
1677
|
-
const
|
|
1678
|
-
|
|
1679
|
-
return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1680
|
-
}
|
|
1681
|
-
if (!hasRole(session.user.role)) {
|
|
1682
|
-
return server.NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
1683
|
-
}
|
|
1684
|
-
return null;
|
|
1719
|
+
const result = await requireAdminApi();
|
|
1720
|
+
return result instanceof server.NextResponse ? result : null;
|
|
1685
1721
|
}
|
|
1686
1722
|
var createSchema = zod.z.object({
|
|
1687
1723
|
segmentId: zod.z.string().min(1),
|
|
@@ -1780,7 +1816,7 @@ async function sendBroadcastPOST(_request, { params }) {
|
|
|
1780
1816
|
}
|
|
1781
1817
|
var subscriptionSchema = zod.z.object({ subscribed: zod.z.boolean() });
|
|
1782
1818
|
async function updateSubscriptionPUT(request) {
|
|
1783
|
-
const session = await getSession();
|
|
1819
|
+
const session = await auth.api.getSession({ headers: await headers.headers(), query: { disableCookieCache: true } });
|
|
1784
1820
|
if (!(session == null ? void 0 : session.user)) {
|
|
1785
1821
|
return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1786
1822
|
}
|