@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/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,12 +230,11 @@ __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",
|
|
232
237
|
"/changelog",
|
|
233
|
-
"/changelog-template",
|
|
234
238
|
"/privacy",
|
|
235
239
|
"/terms"
|
|
236
240
|
];
|
|
@@ -293,7 +297,10 @@ var sessions = pgCore.pgTable("session", {
|
|
|
293
297
|
// Set by better-auth's admin plugin while this session is an admin
|
|
294
298
|
// impersonating another user; holds the impersonating admin's user id.
|
|
295
299
|
impersonatedBy: pgCore.text("impersonatedBy")
|
|
296
|
-
})
|
|
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
|
+
]);
|
|
297
304
|
var accounts = pgCore.pgTable("account", {
|
|
298
305
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
299
306
|
accountId: pgCore.text("accountId").notNull(),
|
|
@@ -342,7 +349,10 @@ var verifications = pgCore.pgTable("verification", {
|
|
|
342
349
|
});
|
|
343
350
|
var activityLogs = pgCore.pgTable("activity_log", {
|
|
344
351
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
345
|
-
|
|
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"),
|
|
346
356
|
action: ActivityActionEnum("action").notNull(),
|
|
347
357
|
description: pgCore.text("description").notNull(),
|
|
348
358
|
ipAddress: pgCore.text("ipAddress"),
|
|
@@ -358,7 +368,11 @@ var activityLogs = pgCore.pgTable("activity_log", {
|
|
|
358
368
|
country: pgCore.text("country"),
|
|
359
369
|
city: pgCore.text("city"),
|
|
360
370
|
createdAt: pgCore.timestamp("createdAt").notNull().defaultNow()
|
|
361
|
-
})
|
|
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
|
+
]);
|
|
362
376
|
var deviceFingerprints = pgCore.pgTable("device_fingerprint", {
|
|
363
377
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
364
378
|
userId: pgCore.text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
@@ -473,7 +487,9 @@ var envSchema = zod.z.object({
|
|
|
473
487
|
RESEND_MARKETING_SEGMENT_ID: zod.z.string().default(""),
|
|
474
488
|
// Sender for every transactional email. Must be on a domain verified in
|
|
475
489
|
// your Resend account.
|
|
476
|
-
|
|
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>"),
|
|
477
493
|
// Display name for this deployment — shown as the authenticator-app label
|
|
478
494
|
// (2FA issuer) and the passkey relying-party name. Consuming projects set
|
|
479
495
|
// this in their own .env; defaults to the template name.
|
|
@@ -483,6 +499,9 @@ var envSchema = zod.z.object({
|
|
|
483
499
|
// a comma-separated list and sends through Resend (needs RESEND_API_KEY).
|
|
484
500
|
FEEDBACK_DISCORD_WEBHOOK_URL: zod.z.string().default(""),
|
|
485
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"),
|
|
486
505
|
// Web Push (example, see lib/push.ts). Generate keys with
|
|
487
506
|
// `bunx web-push generate-vapid-keys`. Blank = the notifications card is hidden.
|
|
488
507
|
// The public key is also read in the browser as NEXT_PUBLIC_VAPID_PUBLIC_KEY.
|
|
@@ -499,7 +518,12 @@ var envSchema = zod.z.object({
|
|
|
499
518
|
DB_DRIVER: zod.z.enum(["pg", "neon"]).default("pg"),
|
|
500
519
|
// Only relevant when DB_DRIVER=pg — whether the target Postgres server has SSL
|
|
501
520
|
// enabled. Self-hosted Postgres (e.g. via Docker/Dokploy) typically does not.
|
|
502
|
-
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")
|
|
503
527
|
});
|
|
504
528
|
|
|
505
529
|
// config/env.ts
|
|
@@ -513,24 +537,47 @@ if (!results.success) {
|
|
|
513
537
|
}
|
|
514
538
|
var config = results.data;
|
|
515
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
|
+
|
|
516
548
|
// server/db/index.ts
|
|
517
549
|
var db;
|
|
518
550
|
if (config.DB_DRIVER === "pg") {
|
|
519
551
|
const pool = new pg.Pool({
|
|
520
552
|
connectionString: config.DATABASE_URL,
|
|
521
|
-
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
|
|
522
558
|
});
|
|
523
559
|
db = nodePostgres.drizzle(pool, {
|
|
524
560
|
schema: schema_exports,
|
|
525
|
-
logger:
|
|
561
|
+
logger: process.env.NODE_ENV === "development"
|
|
526
562
|
});
|
|
527
563
|
console.log("\u{1F7E1} Using PostgreSQL (pg) driver");
|
|
528
|
-
} else if (config.DB_DRIVER === "neon") {
|
|
529
|
-
const sql4 = serverless.neon(config.DATABASE_URL);
|
|
530
|
-
db = neonHttp.drizzle(sql4, { schema: schema_exports, logger: true });
|
|
531
|
-
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
532
564
|
} else {
|
|
533
|
-
|
|
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);
|
|
534
581
|
}
|
|
535
582
|
|
|
536
583
|
// node_modules/@better-auth/utils/dist/base32.mjs
|
|
@@ -539,9 +586,7 @@ function getAlphabet(hex2) {
|
|
|
539
586
|
}
|
|
540
587
|
function createDecodeMap(alphabet) {
|
|
541
588
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
542
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
543
|
-
decodeMap.set(alphabet[i], i);
|
|
544
|
-
}
|
|
589
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
545
590
|
return decodeMap;
|
|
546
591
|
}
|
|
547
592
|
function base32Encode(data, alphabet, padding) {
|
|
@@ -556,9 +601,7 @@ function base32Encode(data, alphabet, padding) {
|
|
|
556
601
|
result += alphabet[buffer >> shift & 31];
|
|
557
602
|
}
|
|
558
603
|
}
|
|
559
|
-
if (shift > 0)
|
|
560
|
-
result += alphabet[buffer << 5 - shift & 31];
|
|
561
|
-
}
|
|
604
|
+
if (shift > 0) result += alphabet[buffer << 5 - shift & 31];
|
|
562
605
|
if (padding) {
|
|
563
606
|
const padCount = (8 - result.length % 8) % 8;
|
|
564
607
|
result += "=".repeat(padCount);
|
|
@@ -571,12 +614,9 @@ function base32Decode(data, alphabet) {
|
|
|
571
614
|
let buffer = 0;
|
|
572
615
|
let bitsCollected = 0;
|
|
573
616
|
for (const char of data) {
|
|
574
|
-
if (char === "=")
|
|
575
|
-
break;
|
|
617
|
+
if (char === "=") break;
|
|
576
618
|
const value = decodeMap.get(char);
|
|
577
|
-
if (value === void 0) {
|
|
578
|
-
throw new Error(`Invalid Base32 character: ${char}`);
|
|
579
|
-
}
|
|
619
|
+
if (value === void 0) throw new Error(`Invalid Base32 character: ${char}`);
|
|
580
620
|
buffer = buffer << 5 | value;
|
|
581
621
|
bitsCollected += 5;
|
|
582
622
|
while (bitsCollected >= 8) {
|
|
@@ -588,68 +628,34 @@ function base32Decode(data, alphabet) {
|
|
|
588
628
|
}
|
|
589
629
|
var base32 = {
|
|
590
630
|
/**
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
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
|
+
*/
|
|
596
636
|
encode(data, options = {}) {
|
|
597
637
|
var _a;
|
|
598
638
|
const alphabet = getAlphabet();
|
|
599
|
-
|
|
600
|
-
return base32Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
639
|
+
return base32Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
601
640
|
},
|
|
602
641
|
/**
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
642
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
643
|
+
* @param data - The Base32 encoded string or ArrayBuffer/TypedArray.
|
|
644
|
+
* @returns The decoded Uint8Array.
|
|
645
|
+
*/
|
|
607
646
|
decode(data) {
|
|
608
|
-
if (typeof data !== "string")
|
|
609
|
-
data = new TextDecoder().decode(data);
|
|
610
|
-
}
|
|
647
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
611
648
|
const alphabet = getAlphabet();
|
|
612
649
|
return base32Decode(data, alphabet);
|
|
613
650
|
}
|
|
614
651
|
};
|
|
615
652
|
|
|
616
|
-
// node_modules/@better-auth/utils/dist/
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
if (data.byteLength === 0) {
|
|
624
|
-
return "";
|
|
625
|
-
}
|
|
626
|
-
const buffer = new Uint8Array(data);
|
|
627
|
-
let result = "";
|
|
628
|
-
for (const byte of buffer) {
|
|
629
|
-
result += byte.toString(16).padStart(2, "0");
|
|
630
|
-
}
|
|
631
|
-
return result;
|
|
632
|
-
},
|
|
633
|
-
decode: (data) => {
|
|
634
|
-
if (!data) {
|
|
635
|
-
return "";
|
|
636
|
-
}
|
|
637
|
-
if (typeof data === "string") {
|
|
638
|
-
if (data.length % 2 !== 0) {
|
|
639
|
-
throw new Error("Invalid hexadecimal string");
|
|
640
|
-
}
|
|
641
|
-
if (!new RegExp(`^[${hexadecimal}]+$`).test(data)) {
|
|
642
|
-
throw new Error("Invalid hexadecimal string");
|
|
643
|
-
}
|
|
644
|
-
const result = new Uint8Array(data.length / 2);
|
|
645
|
-
for (let i = 0; i < data.length; i += 2) {
|
|
646
|
-
result[i / 2] = parseInt(data.slice(i, i + 2), 16);
|
|
647
|
-
}
|
|
648
|
-
return new TextDecoder().decode(result);
|
|
649
|
-
}
|
|
650
|
-
return new TextDecoder().decode(data);
|
|
651
|
-
}
|
|
652
|
-
};
|
|
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
|
+
}
|
|
653
659
|
|
|
654
660
|
// node_modules/@better-auth/utils/dist/base64.mjs
|
|
655
661
|
function getAlphabet2(urlSafe) {
|
|
@@ -667,9 +673,7 @@ function base64Encode(data, alphabet, padding) {
|
|
|
667
673
|
result += alphabet[buffer >> shift & 63];
|
|
668
674
|
}
|
|
669
675
|
}
|
|
670
|
-
if (shift > 0)
|
|
671
|
-
result += alphabet[buffer << 6 - shift & 63];
|
|
672
|
-
}
|
|
676
|
+
if (shift > 0) result += alphabet[buffer << 6 - shift & 63];
|
|
673
677
|
if (padding) {
|
|
674
678
|
const padCount = (4 - result.length % 4) % 4;
|
|
675
679
|
result += "=".repeat(padCount);
|
|
@@ -678,19 +682,14 @@ function base64Encode(data, alphabet, padding) {
|
|
|
678
682
|
}
|
|
679
683
|
function base64Decode(data, alphabet) {
|
|
680
684
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
681
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
682
|
-
decodeMap.set(alphabet[i], i);
|
|
683
|
-
}
|
|
685
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
684
686
|
const result = [];
|
|
685
687
|
let buffer = 0;
|
|
686
688
|
let bitsCollected = 0;
|
|
687
689
|
for (const char of data) {
|
|
688
|
-
if (char === "=")
|
|
689
|
-
break;
|
|
690
|
+
if (char === "=") break;
|
|
690
691
|
const value = decodeMap.get(char);
|
|
691
|
-
if (value === void 0) {
|
|
692
|
-
throw new Error(`Invalid Base64 character: ${char}`);
|
|
693
|
-
}
|
|
692
|
+
if (value === void 0) throw new Error(`Invalid Base64 character: ${char}`);
|
|
694
693
|
buffer = buffer << 6 | value;
|
|
695
694
|
bitsCollected += 6;
|
|
696
695
|
if (bitsCollected >= 8) {
|
|
@@ -704,15 +703,11 @@ var base64 = {
|
|
|
704
703
|
encode(data, options = {}) {
|
|
705
704
|
var _a;
|
|
706
705
|
const alphabet = getAlphabet2(false);
|
|
707
|
-
|
|
708
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
706
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
709
707
|
},
|
|
710
708
|
decode(data) {
|
|
711
|
-
if (typeof data !== "string")
|
|
712
|
-
|
|
713
|
-
}
|
|
714
|
-
const urlSafe = data.includes("-") || data.includes("_");
|
|
715
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
709
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
710
|
+
const alphabet = getAlphabet2(data.includes("-") || data.includes("_"));
|
|
716
711
|
return base64Decode(data, alphabet);
|
|
717
712
|
}
|
|
718
713
|
};
|
|
@@ -720,152 +715,142 @@ var base64Url = {
|
|
|
720
715
|
encode(data, options = {}) {
|
|
721
716
|
var _a;
|
|
722
717
|
const alphabet = getAlphabet2(true);
|
|
723
|
-
|
|
724
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
718
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
725
719
|
},
|
|
726
720
|
decode(data) {
|
|
727
|
-
|
|
728
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
729
|
-
return base64Decode(data, alphabet);
|
|
721
|
+
return base64Decode(data, getAlphabet2(data.includes("-") || data.includes("_")));
|
|
730
722
|
}
|
|
731
723
|
};
|
|
732
724
|
|
|
733
|
-
// node_modules/@
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
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;
|
|
739
760
|
}
|
|
740
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
|
+
|
|
741
780
|
// node_modules/@better-auth/utils/dist/hmac.mjs
|
|
742
781
|
var createHMAC = (algorithm = "SHA-256", encoding = "none") => {
|
|
743
|
-
const
|
|
782
|
+
const hmac2 = {
|
|
744
783
|
importKey: async (key, keyUsage) => {
|
|
745
|
-
return getWebcryptoSubtle().importKey(
|
|
746
|
-
"
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
false,
|
|
750
|
-
[keyUsage]
|
|
751
|
-
);
|
|
784
|
+
return getWebcryptoSubtle().importKey("raw", toBufferSource(key), {
|
|
785
|
+
name: "HMAC",
|
|
786
|
+
hash: { name: algorithm }
|
|
787
|
+
}, false, [keyUsage]);
|
|
752
788
|
},
|
|
753
789
|
sign: async (hmacKey, data) => {
|
|
754
|
-
if (typeof hmacKey === "string")
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
hmacKey,
|
|
760
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
761
|
-
);
|
|
762
|
-
if (encoding === "hex") {
|
|
763
|
-
return hex.encode(signature);
|
|
764
|
-
}
|
|
765
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
766
|
-
return base64Url.encode(signature, {
|
|
767
|
-
padding: encoding !== "base64urlnopad"
|
|
768
|
-
});
|
|
769
|
-
}
|
|
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" });
|
|
770
795
|
return signature;
|
|
771
796
|
},
|
|
772
797
|
verify: async (hmacKey, data, signature) => {
|
|
773
|
-
if (typeof hmacKey === "string")
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
signature = hex.decode(signature);
|
|
778
|
-
}
|
|
779
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
780
|
-
signature = await base64.decode(signature);
|
|
781
|
-
}
|
|
782
|
-
return getWebcryptoSubtle().verify(
|
|
783
|
-
"HMAC",
|
|
784
|
-
hmacKey,
|
|
785
|
-
typeof signature === "string" ? new TextEncoder().encode(signature) : signature,
|
|
786
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
787
|
-
);
|
|
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));
|
|
788
802
|
}
|
|
789
803
|
};
|
|
790
|
-
return
|
|
804
|
+
return hmac2;
|
|
791
805
|
};
|
|
792
806
|
|
|
793
807
|
// node_modules/@better-auth/utils/dist/otp.mjs
|
|
794
808
|
var defaultPeriod = 30;
|
|
795
809
|
var defaultDigits = 6;
|
|
810
|
+
var hmac = createHMAC("SHA-1");
|
|
796
811
|
function constantTimeEqualOTP(input, expected) {
|
|
797
812
|
let difference = input.length ^ expected.length;
|
|
798
|
-
for (let i = 0; i < expected.length; i++)
|
|
799
|
-
difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
800
|
-
}
|
|
813
|
+
for (let i = 0; i < expected.length; i++) difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
801
814
|
return difference === 0;
|
|
802
815
|
}
|
|
803
|
-
async function generateHOTP(
|
|
804
|
-
counter,
|
|
805
|
-
digits,
|
|
806
|
-
hash = "SHA-1"
|
|
807
|
-
}) {
|
|
816
|
+
async function generateHOTP(key, { counter, digits }) {
|
|
808
817
|
const _digits = digits != null ? digits : defaultDigits;
|
|
809
|
-
if (_digits < 1 || _digits > 8)
|
|
810
|
-
|
|
811
|
-
}
|
|
812
|
-
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);
|
|
813
820
|
new DataView(buffer).setBigUint64(0, BigInt(counter), false);
|
|
814
821
|
const bytes = new Uint8Array(buffer);
|
|
815
|
-
const
|
|
822
|
+
const signature = await hmac.sign(key, bytes);
|
|
823
|
+
const hmacResult = new Uint8Array(signature);
|
|
816
824
|
const offset = hmacResult[hmacResult.length - 1] & 15;
|
|
817
|
-
|
|
818
|
-
const otp = truncated % 10 ** _digits;
|
|
819
|
-
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");
|
|
820
826
|
}
|
|
821
|
-
async function generateTOTP(
|
|
827
|
+
async function generateTOTP(key, options) {
|
|
822
828
|
var _a, _b;
|
|
823
829
|
const digits = (_a = options == null ? void 0 : options.digits) != null ? _a : defaultDigits;
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
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
|
+
});
|
|
828
835
|
}
|
|
829
|
-
async function verifyTOTP(otp, {
|
|
830
|
-
window = 1,
|
|
831
|
-
digits = defaultDigits,
|
|
832
|
-
secret,
|
|
833
|
-
period = defaultPeriod
|
|
834
|
-
}) {
|
|
836
|
+
async function verifyTOTP(otp, { window = 1, digits = defaultDigits, key, period = defaultPeriod }) {
|
|
835
837
|
const milliseconds = period * 1e3;
|
|
836
838
|
const counter = Math.floor(Date.now() / milliseconds);
|
|
837
839
|
let matched = false;
|
|
838
|
-
for (let i = -window; i <= window; i++) {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
});
|
|
843
|
-
matched = constantTimeEqualOTP(otp, generatedOTP) || matched;
|
|
844
|
-
}
|
|
840
|
+
for (let i = -window; i <= window; i++) matched = constantTimeEqualOTP(otp, await generateHOTP(key, {
|
|
841
|
+
counter: counter + i,
|
|
842
|
+
digits
|
|
843
|
+
})) || matched;
|
|
845
844
|
return matched;
|
|
846
845
|
}
|
|
847
|
-
function generateQRCode({
|
|
848
|
-
issuer
|
|
849
|
-
account,
|
|
850
|
-
secret,
|
|
851
|
-
digits = defaultDigits,
|
|
852
|
-
period = defaultPeriod
|
|
853
|
-
}) {
|
|
854
|
-
const encodedIssuer = encodeURIComponent(issuer);
|
|
855
|
-
const encodedAccountName = encodeURIComponent(account);
|
|
856
|
-
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)}`;
|
|
857
848
|
const params = new URLSearchParams({
|
|
858
|
-
secret: base32.encode(secret, {
|
|
859
|
-
padding: false
|
|
860
|
-
}),
|
|
849
|
+
secret: base32.encode(secret, { padding: false }),
|
|
861
850
|
issuer
|
|
862
851
|
});
|
|
863
|
-
if (digits !== void 0)
|
|
864
|
-
|
|
865
|
-
}
|
|
866
|
-
if (period !== void 0) {
|
|
867
|
-
params.set("period", period.toString());
|
|
868
|
-
}
|
|
852
|
+
if (digits !== void 0) params.set("digits", digits.toString());
|
|
853
|
+
if (period !== void 0) params.set("period", period.toString());
|
|
869
854
|
return `${baseURI}?${params.toString()}`;
|
|
870
855
|
}
|
|
871
856
|
var createOTP = (secret, opts) => {
|
|
@@ -873,14 +858,38 @@ var createOTP = (secret, opts) => {
|
|
|
873
858
|
const digits = (_a = void 0 ) != null ? _a : defaultDigits;
|
|
874
859
|
const period = (_b = void 0 ) != null ? _b : defaultPeriod;
|
|
875
860
|
return {
|
|
876
|
-
hotp: (counter) =>
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
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
|
+
}
|
|
880
889
|
};
|
|
881
890
|
};
|
|
882
891
|
|
|
883
|
-
// lib/two-factor.ts
|
|
892
|
+
// lib/auth/two-factor.ts
|
|
884
893
|
var CHALLENGED_PATHS = ["/callback/:id", "/one-tap/callback"];
|
|
885
894
|
var CODE_REQUIRED_PATHS = ["/two-factor/disable", "/two-factor/generate-backup-codes"];
|
|
886
895
|
function twoFactorPlugins(baseURL, { issuer, passwordless = false, challengeAfterOAuth = false }) {
|
|
@@ -953,6 +962,8 @@ async function logActivity({
|
|
|
953
962
|
try {
|
|
954
963
|
await db.insert(activityLogs).values({
|
|
955
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})`,
|
|
956
967
|
action,
|
|
957
968
|
description,
|
|
958
969
|
ipAddress: ipAddress || null,
|
|
@@ -973,7 +984,7 @@ var countryNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
|
973
984
|
function getClientIp(headers3) {
|
|
974
985
|
var _a;
|
|
975
986
|
const forwardedFor = headers3 == null ? void 0 : headers3.get("x-forwarded-for");
|
|
976
|
-
if (forwardedFor) return forwardedFor.split(",")
|
|
987
|
+
if (forwardedFor) return forwardedFor.split(",").at(-1).trim();
|
|
977
988
|
return (_a = headers3 == null ? void 0 : headers3.get("x-real-ip")) != null ? _a : null;
|
|
978
989
|
}
|
|
979
990
|
function parseUserAgent(userAgent) {
|
|
@@ -1012,11 +1023,21 @@ function formatLocation({ country, city }) {
|
|
|
1012
1023
|
return [city, country].filter(Boolean).join(", ");
|
|
1013
1024
|
}
|
|
1014
1025
|
|
|
1015
|
-
// lib/cookie-names.ts
|
|
1026
|
+
// lib/security/cookie-names.ts
|
|
1016
1027
|
var LOGIN_REFERRER_COOKIE = "login_referrer";
|
|
1017
1028
|
var DEVICE_FINGERPRINT_HEADER = "x-device-fingerprint";
|
|
1018
1029
|
|
|
1019
|
-
// 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
|
|
1020
1041
|
var WINDOW_MS = 15 * 60 * 1e3;
|
|
1021
1042
|
var MAX = 10;
|
|
1022
1043
|
var MAX_IP = MAX * 3;
|
|
@@ -1027,7 +1048,7 @@ function isOverLimit(row, now, max = MAX) {
|
|
|
1027
1048
|
return row.count >= max;
|
|
1028
1049
|
}
|
|
1029
1050
|
|
|
1030
|
-
// lib/auth
|
|
1051
|
+
// lib/auth/throttle.ts
|
|
1031
1052
|
async function isDeviceThrottled(fingerprint, max) {
|
|
1032
1053
|
try {
|
|
1033
1054
|
const [row] = await db.select({ count: authThrottle.count, windowStart: authThrottle.windowStart }).from(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint)).limit(1);
|
|
@@ -1051,8 +1072,10 @@ async function recordDeviceAttempt(fingerprint, meta) {
|
|
|
1051
1072
|
await db.insert(authThrottle).values(__spreadValues({ fingerprint, count: 1, windowStart: now }, seen)).onConflictDoUpdate({
|
|
1052
1073
|
target: authThrottle.fingerprint,
|
|
1053
1074
|
set: __spreadValues({
|
|
1054
|
-
|
|
1055
|
-
|
|
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`
|
|
1056
1079
|
}, seen)
|
|
1057
1080
|
});
|
|
1058
1081
|
} catch (error) {
|
|
@@ -1071,15 +1094,9 @@ async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
|
1071
1094
|
console.error("auth-throttle prune failed", error);
|
|
1072
1095
|
}
|
|
1073
1096
|
}
|
|
1074
|
-
async function clearDeviceThrottle(fingerprint) {
|
|
1075
|
-
try {
|
|
1076
|
-
await db.delete(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint));
|
|
1077
|
-
} catch (error) {
|
|
1078
|
-
console.error("auth-throttle clear failed", error);
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
1097
|
var SETTINGS_ROW_ID = "default";
|
|
1082
1098
|
var CACHE_TTL_MS = 1e4;
|
|
1099
|
+
var FAILURE_CACHE_TTL_MS = 5e3;
|
|
1083
1100
|
var cached = null;
|
|
1084
1101
|
function fallbackSettings() {
|
|
1085
1102
|
return {
|
|
@@ -1122,7 +1139,9 @@ async function getSystemSettings() {
|
|
|
1122
1139
|
return value;
|
|
1123
1140
|
} catch (error) {
|
|
1124
1141
|
console.error("Failed to load system settings, failing open:", error);
|
|
1125
|
-
|
|
1142
|
+
const value = fallbackSettings();
|
|
1143
|
+
cached = { value, expiresAt: now + FAILURE_CACHE_TTL_MS };
|
|
1144
|
+
return value;
|
|
1126
1145
|
}
|
|
1127
1146
|
}
|
|
1128
1147
|
async function getEffectiveAuthFlags() {
|
|
@@ -1187,7 +1206,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1187
1206
|
userAgent: (_b = (_a = ctx.headers) == null ? void 0 : _a.get("user-agent")) != null ? _b : null
|
|
1188
1207
|
});
|
|
1189
1208
|
if (!config.RESEND_API_KEY) return;
|
|
1190
|
-
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (
|
|
1209
|
+
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (init_passkey_changed(), passkey_changed_exports));
|
|
1191
1210
|
await (await getResend()).emails.send({
|
|
1192
1211
|
from: EMAIL_FROM,
|
|
1193
1212
|
to: [user.email],
|
|
@@ -1199,7 +1218,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1199
1218
|
location: formatLocation(lookupGeoLocation(ip)),
|
|
1200
1219
|
ipAddress: ip || "Unknown",
|
|
1201
1220
|
when: (/* @__PURE__ */ new Date()).toUTCString(),
|
|
1202
|
-
manageUrl: `${
|
|
1221
|
+
manageUrl: `${getBaseUrl()}/dashboard/settings`
|
|
1203
1222
|
})
|
|
1204
1223
|
});
|
|
1205
1224
|
} catch (error) {
|
|
@@ -1250,6 +1269,15 @@ async function packageSessionCreated(log, ...[session, context]) {
|
|
|
1250
1269
|
console.error("Failed to log login activity", error);
|
|
1251
1270
|
}
|
|
1252
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
|
+
}
|
|
1253
1281
|
function createAuth(overrides = {}) {
|
|
1254
1282
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1255
1283
|
const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
|
|
@@ -1265,7 +1293,7 @@ function createAuth(overrides = {}) {
|
|
|
1265
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: {...} })."
|
|
1266
1294
|
);
|
|
1267
1295
|
}
|
|
1268
|
-
const baseURL =
|
|
1296
|
+
const baseURL = getBaseUrl();
|
|
1269
1297
|
const log = (_a = overrides.logActivity) != null ? _a : logActivity;
|
|
1270
1298
|
const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
|
|
1271
1299
|
issuer: config.APP_NAME,
|
|
@@ -1313,7 +1341,7 @@ function createAuth(overrides = {}) {
|
|
|
1313
1341
|
// callbackURL) — see app/(auth)/forgot-password and reset-password for
|
|
1314
1342
|
// the pages this points at.
|
|
1315
1343
|
async sendResetPassword({ user, url }) {
|
|
1316
|
-
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (
|
|
1344
|
+
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (init_reset_password(), reset_password_exports));
|
|
1317
1345
|
await (await getResend()).emails.send({
|
|
1318
1346
|
from: EMAIL_FROM,
|
|
1319
1347
|
to: [user.email],
|
|
@@ -1329,8 +1357,11 @@ function createAuth(overrides = {}) {
|
|
|
1329
1357
|
// callback that flips users.emailVerified on click.
|
|
1330
1358
|
emailVerification: {
|
|
1331
1359
|
autoSignInAfterVerification: true,
|
|
1360
|
+
async afterEmailVerification(user) {
|
|
1361
|
+
await promoteFirstAdmin(user);
|
|
1362
|
+
},
|
|
1332
1363
|
async sendVerificationEmail({ user, url }) {
|
|
1333
|
-
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (
|
|
1364
|
+
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (init_verify_email(), verify_email_exports));
|
|
1334
1365
|
await (await getResend()).emails.send({
|
|
1335
1366
|
from: EMAIL_FROM,
|
|
1336
1367
|
to: [user.email],
|
|
@@ -1372,6 +1403,7 @@ function createAuth(overrides = {}) {
|
|
|
1372
1403
|
create: {
|
|
1373
1404
|
async after(user, context) {
|
|
1374
1405
|
var _a2, _b2, _c2, _d2;
|
|
1406
|
+
await promoteFirstAdmin(user);
|
|
1375
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));
|
|
1376
1408
|
}
|
|
1377
1409
|
}
|
|
@@ -1395,7 +1427,7 @@ function createAuth(overrides = {}) {
|
|
|
1395
1427
|
// available together.
|
|
1396
1428
|
hooks: {
|
|
1397
1429
|
before: api.createAuthMiddleware(async (ctx) => {
|
|
1398
|
-
var _a2, _b2, _c2, _d2;
|
|
1430
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
1399
1431
|
if (ctx.path === "/sign-in/email" || ctx.path === "/sign-up/email") {
|
|
1400
1432
|
const fingerprint = (_a2 = ctx.headers) == null ? void 0 : _a2.get(DEVICE_FINGERPRINT_HEADER);
|
|
1401
1433
|
const ip = getClientIp(ctx.headers);
|
|
@@ -1429,6 +1461,9 @@ function createAuth(overrides = {}) {
|
|
|
1429
1461
|
}
|
|
1430
1462
|
return;
|
|
1431
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
|
+
}
|
|
1432
1467
|
if (ctx.path === "/admin/impersonate-user" && overrides.impersonation === false) {
|
|
1433
1468
|
throw new api.APIError("FORBIDDEN", { message: "Impersonation is turned off." });
|
|
1434
1469
|
}
|
|
@@ -1439,8 +1474,8 @@ function createAuth(overrides = {}) {
|
|
|
1439
1474
|
throw new api.APIError("FORBIDDEN", { message: "Stop impersonating before deleting an account." });
|
|
1440
1475
|
}
|
|
1441
1476
|
if (current2.user.role === "admin") {
|
|
1442
|
-
const [
|
|
1443
|
-
if (
|
|
1477
|
+
const [other] = await db.select({ n: drizzleOrm.sql`1` }).from(users).where(otherActiveAdminExists([current2.user.id])).limit(1);
|
|
1478
|
+
if (!other) {
|
|
1444
1479
|
throw new api.APIError("FORBIDDEN", { message: "You're the only admin. Promote another user to admin first." });
|
|
1445
1480
|
}
|
|
1446
1481
|
}
|
|
@@ -1453,7 +1488,7 @@ function createAuth(overrides = {}) {
|
|
|
1453
1488
|
await log({
|
|
1454
1489
|
userId: current.session.impersonatedBy,
|
|
1455
1490
|
action: "impersonation_stopped",
|
|
1456
|
-
description: `Admin stopped impersonating ${(
|
|
1491
|
+
description: `Admin stopped impersonating ${(_e2 = (_d2 = target[0]) == null ? void 0 : _d2.email) != null ? _e2 : current.session.userId}`,
|
|
1457
1492
|
metadata: { impersonatedUserId: current.session.userId }
|
|
1458
1493
|
});
|
|
1459
1494
|
}
|
|
@@ -1489,8 +1524,6 @@ function createAuth(overrides = {}) {
|
|
|
1489
1524
|
if (failed) {
|
|
1490
1525
|
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
1491
1526
|
await logFailedLogin(ctx, log);
|
|
1492
|
-
} else {
|
|
1493
|
-
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
1494
1527
|
}
|
|
1495
1528
|
})
|
|
1496
1529
|
},
|
|
@@ -1571,14 +1604,25 @@ var auth = new Proxy({}, {
|
|
|
1571
1604
|
return Reflect.getOwnPropertyDescriptor(getDefaultAuth(), prop);
|
|
1572
1605
|
}
|
|
1573
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
|
|
1574
1617
|
var getCurrentSession = react.cache(async () => {
|
|
1575
1618
|
const session = await auth.api.getSession({
|
|
1576
|
-
headers: await headers.headers()
|
|
1619
|
+
headers: await headers.headers(),
|
|
1620
|
+
query: { disableCookieCache: true }
|
|
1577
1621
|
});
|
|
1578
1622
|
return session;
|
|
1579
1623
|
});
|
|
1580
1624
|
react.cache(async () => {
|
|
1581
|
-
var _a;
|
|
1625
|
+
var _a, _b, _c;
|
|
1582
1626
|
const session = await getCurrentSession();
|
|
1583
1627
|
if (!(session == null ? void 0 : session.user)) {
|
|
1584
1628
|
navigation.redirect("/login");
|
|
@@ -1590,13 +1634,13 @@ react.cache(async () => {
|
|
|
1590
1634
|
});
|
|
1591
1635
|
navigation.redirect("/login?error=account_banned");
|
|
1592
1636
|
}
|
|
1593
|
-
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 }) });
|
|
1594
1638
|
});
|
|
1595
|
-
function
|
|
1596
|
-
|
|
1597
|
-
{
|
|
1598
|
-
|
|
1599
|
-
|
|
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;
|
|
1600
1644
|
}
|
|
1601
1645
|
var MARKETING_SEGMENT_ID = config.RESEND_MARKETING_SEGMENT_ID;
|
|
1602
1646
|
async function setSubscribed(email, name, subscribed) {
|
|
@@ -1620,7 +1664,7 @@ async function setSubscribed(email, name, subscribed) {
|
|
|
1620
1664
|
}
|
|
1621
1665
|
}
|
|
1622
1666
|
|
|
1623
|
-
// lib/marketing-email.ts
|
|
1667
|
+
// lib/email/marketing-email.ts
|
|
1624
1668
|
var UNSUBSCRIBE_PLACEHOLDER = "{{{RESEND_UNSUBSCRIBE_URL}}}";
|
|
1625
1669
|
var escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1626
1670
|
function textToBroadcastHtml(text2) {
|
|
@@ -1670,19 +1714,10 @@ function unexpectedErrorMessage(error, message = "Something went wrong. Please t
|
|
|
1670
1714
|
return `${message} (ref: ${ref})`;
|
|
1671
1715
|
}
|
|
1672
1716
|
|
|
1673
|
-
// lib/marketing
|
|
1674
|
-
async function getSession() {
|
|
1675
|
-
return auth.api.getSession({ headers: await headers.headers() });
|
|
1676
|
-
}
|
|
1717
|
+
// lib/marketing/route.ts
|
|
1677
1718
|
async function requireAdmin() {
|
|
1678
|
-
const
|
|
1679
|
-
|
|
1680
|
-
return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1681
|
-
}
|
|
1682
|
-
if (!hasRole(session.user.role)) {
|
|
1683
|
-
return server.NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
1684
|
-
}
|
|
1685
|
-
return null;
|
|
1719
|
+
const result = await requireAdminApi();
|
|
1720
|
+
return result instanceof server.NextResponse ? result : null;
|
|
1686
1721
|
}
|
|
1687
1722
|
var createSchema = zod.z.object({
|
|
1688
1723
|
segmentId: zod.z.string().min(1),
|
|
@@ -1781,7 +1816,7 @@ async function sendBroadcastPOST(_request, { params }) {
|
|
|
1781
1816
|
}
|
|
1782
1817
|
var subscriptionSchema = zod.z.object({ subscribed: zod.z.boolean() });
|
|
1783
1818
|
async function updateSubscriptionPUT(request) {
|
|
1784
|
-
const session = await getSession();
|
|
1819
|
+
const session = await auth.api.getSession({ headers: await headers.headers(), query: { disableCookieCache: true } });
|
|
1785
1820
|
if (!(session == null ? void 0 : session.user)) {
|
|
1786
1821
|
return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1787
1822
|
}
|