@xk2800/nextjs-template 0.7.2-beta.1 → 0.7.2-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/components/auth/{loginErrorRecovery.tsx → forms/login-error-recovery.tsx} +1 -1
- package/components/auth/{emailPasswordLogin.tsx → forms/login-form.tsx} +8 -8
- package/components/auth/{emailPasswordSignup.tsx → forms/signup-form.tsx} +11 -8
- package/components/auth/{authCard.tsx → layout/auth-card.tsx} +5 -5
- package/components/auth/{authShell.tsx → layout/auth-shell.tsx} +17 -5
- package/components/auth/{oneTap.tsx → methods/one-tap.tsx} +2 -2
- package/components/auth/{passkeyLogin.tsx → methods/passkey-login.tsx} +2 -2
- package/components/auth/{socialLogin.tsx → methods/social-login.tsx} +3 -3
- package/components/auth/{twoFactorVerifyForm.tsx → mfa/two-factor-verify-form.tsx} +5 -5
- package/components/auth/{forgotPasswordForm.tsx → recovery/forgot-password-form.tsx} +4 -4
- package/components/auth/{resetPasswordForm.tsx → recovery/reset-password-form.tsx} +4 -4
- package/components/auth/{deviceCheck.tsx → session/device-check.tsx} +3 -3
- package/components/auth/{logoutButtons.tsx → session/logout-buttons.tsx} +2 -2
- package/components/dashboard/admin/{activityLogsSection.tsx → activity-logs/activity-logs-section.tsx} +1 -1
- package/components/dashboard/admin/activity-logs/admin-activity-logs-table.tsx +375 -0
- package/components/dashboard/admin/activity-logs/audit-severity-badge.tsx +50 -0
- package/components/dashboard/admin/activity-logs/security-highlights-collapsible.tsx +129 -0
- package/components/dashboard/admin/{adminActivityLogsSkeleton.tsx → activity-logs/skeletons/activity-logs-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{adminStatsGrid.tsx → home/admin-stats-grid.tsx} +1 -1
- package/components/dashboard/admin/{deviceThrottleCard.tsx → home/device-throttle-card.tsx} +8 -5
- package/components/dashboard/admin/{deviceThrottleTable.tsx → home/device-throttle-table.tsx} +3 -3
- package/components/dashboard/admin/{newDeviceCard.tsx → home/new-device-card.tsx} +6 -2
- package/components/dashboard/admin/{newDeviceTable.tsx → home/new-device-table.tsx} +4 -4
- package/components/dashboard/admin/{sharedDeviceCard.tsx → home/shared-device-card.tsx} +3 -3
- package/components/dashboard/admin/{sharedDeviceTable.tsx → home/shared-device-table.tsx} +3 -3
- package/components/dashboard/admin/{adminStatsGridSkeleton.tsx → home/skeletons/admin-stats-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{broadcastActions.tsx → marketing/broadcast-actions.tsx} +3 -3
- package/components/dashboard/admin/{confirmSendDialog.tsx → marketing/confirm-send-dialog.tsx} +1 -1
- package/components/dashboard/admin/{marketingEmailForm.tsx → marketing/marketing-email-form.tsx} +7 -7
- package/components/dashboard/admin/{marketingSection.tsx → marketing/marketing-section.tsx} +6 -6
- package/components/dashboard/admin/{subscribersCard.tsx → marketing/subscribers-card.tsx} +3 -3
- package/components/dashboard/admin/{feedbackTestForm.tsx → system-settings/feedback-test-form.tsx} +4 -4
- package/components/dashboard/admin/{systemSettingsSkeleton.tsx → system-settings/skeletons/system-settings-skeleton.tsx} +2 -2
- package/components/dashboard/admin/system-settings/system-settings-form.tsx +362 -0
- package/components/dashboard/admin/{systemSettingsSection.tsx → system-settings/system-settings-section.tsx} +3 -2
- package/components/dashboard/admin/users/admin-user-actions.tsx +238 -0
- package/components/dashboard/admin/users/admin-user-profile-card.tsx +70 -0
- package/components/dashboard/admin/users/admin-user-security-card.tsx +47 -0
- package/components/dashboard/admin/users/admin-user-status-card.tsx +89 -0
- package/components/dashboard/admin/{adminUsersTable.tsx → users/admin-users-table.tsx} +129 -132
- package/components/dashboard/admin/{adminUserActivityLogCard.tsx → users/detail/admin-user-activity-log-card.tsx} +3 -3
- package/components/dashboard/admin/{adminUserActivityLogTable.tsx → users/detail/admin-user-activity-log-table.tsx} +3 -3
- package/components/dashboard/admin/{adminUserConsentCard.tsx → users/detail/admin-user-consent-card.tsx} +4 -4
- package/components/dashboard/admin/{adminUserDevicesCard.tsx → users/detail/admin-user-devices-card.tsx} +2 -2
- package/components/dashboard/admin/{adminUserLoginInfoCard.tsx → users/detail/admin-user-login-info-card.tsx} +3 -3
- package/components/dashboard/admin/{adminUserLoginInfoTable.tsx → users/detail/admin-user-login-info-table.tsx} +3 -3
- package/components/dashboard/admin/{adminUserSessionsCard.tsx → users/detail/admin-user-sessions-card.tsx} +5 -5
- package/components/dashboard/admin/{impersonationLogCard.tsx → users/impersonation-log-card.tsx} +10 -5
- package/components/dashboard/admin/users/impersonation-tab.tsx +255 -0
- package/components/dashboard/admin/users/invite-user-dialog.tsx +80 -0
- package/components/dashboard/admin/{revokeAllSessionsButton.tsx → users/revoke-all-sessions.tsx} +5 -3
- package/components/dashboard/admin/{adminUsersSkeleton.tsx → users/skeletons/admin-users-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{usersSection.tsx → users/users-section.tsx} +1 -1
- package/components/dashboard/{errorFeedback.tsx → common/error-feedback.tsx} +1 -1
- package/components/dashboard/{feedbackDialog.tsx → common/feedback-dialog.tsx} +4 -4
- package/components/dashboard/{sectionErrorFallback.tsx → common/section-error-fallback.tsx} +1 -1
- package/components/dashboard/{verifyEmailButton.tsx → common/verify-email-button.tsx} +2 -2
- package/components/dashboard/{appSidebar.tsx → layout/app-sidebar.tsx} +11 -8
- package/components/dashboard/{dashboardHeader.tsx → layout/dashboard-header.tsx} +1 -1
- package/components/dashboard/{impersonationBanner.tsx → layout/impersonation-banner.tsx} +2 -2
- package/components/dashboard/layout/mobile-nav.tsx +95 -0
- package/components/dashboard/{navStyleToggle.tsx → layout/nav-style-toggle.tsx} +1 -1
- package/components/dashboard/{topNav.tsx → layout/top-nav.tsx} +19 -38
- package/components/dashboard/{installAppCard.tsx → overview/install-app-card.tsx} +2 -2
- package/components/dashboard/{accountDetailsCard.tsx → settings/account-details-card.tsx} +5 -5
- package/components/dashboard/{activityLogsCard.tsx → settings/activity-logs-card.tsx} +6 -6
- package/components/dashboard/{activityLogsSection.tsx → settings/activity-logs-section.tsx} +1 -1
- package/components/dashboard/{adminSection.tsx → settings/admin-section.tsx} +2 -2
- package/components/dashboard/{deleteAccountCard.tsx → settings/delete-account-card.tsx} +7 -7
- package/components/dashboard/{marketingUpdatesCard.tsx → settings/marketing-updates-card.tsx} +3 -3
- package/components/dashboard/{marketingUpdatesSection.tsx → settings/marketing-updates-section.tsx} +1 -1
- package/components/dashboard/{passkeysCard.tsx → settings/passkeys-card.tsx} +8 -8
- package/components/dashboard/{profileCard.tsx → settings/profile-card.tsx} +4 -4
- package/components/dashboard/{sessionsCard.tsx → settings/sessions/sessions-card.tsx} +6 -6
- package/components/dashboard/{sessionsSection.tsx → settings/sessions/sessions-section.tsx} +1 -1
- package/components/dashboard/{sessionsCardSkeleton.tsx → settings/sessions/skeletons/sessions-card-skeleton.tsx} +2 -2
- package/components/dashboard/{activityLogsCardSkeleton.tsx → settings/skeletons/activity-logs-card-skeleton.tsx} +2 -2
- package/components/dashboard/{twoFactorCard.tsx → settings/two-factor-card.tsx} +8 -8
- package/components/email/team/workspace-invite.tsx +51 -0
- package/components/email/{send-email-button.tsx → ui/send-email-button.tsx} +1 -1
- package/components/error-boundary.tsx +32 -0
- package/components/settings/appearance/appearance-section.tsx +64 -0
- package/components/settings/index.ts +5 -0
- package/components/settings/notifications/notifications-section.tsx +31 -0
- package/components/settings/profile/profile-section.tsx +38 -0
- package/components/settings/security/security-section.tsx +24 -0
- package/components/settings/settings-nav.tsx +35 -0
- package/components/site/{cookie-banner.tsx → compliance/cookie-banner.tsx} +6 -6
- package/components/site/push/push-notifications-card.tsx +117 -0
- package/components/ui/collapsible.tsx +9 -0
- package/components/ui/column-picker.tsx +1 -1
- package/components/ui/data-table.tsx +1 -1
- package/components/ui/dialog.tsx +46 -13
- package/components/ui/drawer.tsx +88 -0
- package/components/ui/tabs.tsx +52 -0
- package/dist/activity/logger.d.mts +2 -1
- package/dist/activity/logger.d.ts +2 -1
- package/dist/activity/logger.js +66 -15
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +32 -21
- package/dist/activity/queries.d.ts +32 -21
- package/dist/activity/queries.js +86 -22
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +27 -14
- package/dist/activity/queries.mjs.map +1 -1
- package/dist/admin/queries.d.mts +2 -1
- package/dist/admin/queries.d.ts +2 -1
- package/dist/admin/queries.js +48 -17
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +9 -9
- package/dist/admin/queries.mjs.map +1 -1
- package/dist/api/feedback.js +302 -248
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +14 -12
- package/dist/api/feedback.mjs.map +1 -1
- package/dist/api/marketing.js +320 -266
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +16 -25
- package/dist/api/marketing.mjs.map +1 -1
- package/dist/auth/helpers.d.mts +60 -18
- package/dist/auth/helpers.d.ts +60 -18
- package/dist/auth/helpers.js +332 -267
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +9 -9
- package/dist/auth/index.d.mts +86 -47
- package/dist/auth/index.d.ts +86 -47
- package/dist/auth/index.js +296 -244
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +8 -8
- package/dist/auth-client/index.d.mts +1215 -2527
- package/dist/auth-client/index.d.ts +1215 -2527
- package/dist/auth-client/index.js +37 -3
- package/dist/auth-client/index.js.map +1 -1
- package/dist/auth-client/index.mjs +19 -3
- package/dist/auth-client/index.mjs.map +1 -1
- package/dist/{chunk-TE5BEAQB.mjs → chunk-3BH6BVBQ.mjs} +17 -7
- package/dist/chunk-3BH6BVBQ.mjs.map +1 -0
- package/dist/chunk-D56ENLSX.mjs +6 -0
- package/dist/chunk-D56ENLSX.mjs.map +1 -0
- package/dist/{chunk-HUEDEAY3.mjs → chunk-DCPVEZS7.mjs} +14 -4
- package/dist/chunk-DCPVEZS7.mjs.map +1 -0
- package/dist/{chunk-NQELV53D.mjs → chunk-DWLMCMXF.mjs} +4 -4
- package/dist/chunk-DWLMCMXF.mjs.map +1 -0
- package/dist/{chunk-653GF7OT.mjs → chunk-EXMUANQ3.mjs} +4 -4
- package/dist/chunk-EXMUANQ3.mjs.map +1 -0
- package/dist/chunk-LADVCLEQ.mjs +43 -0
- package/dist/chunk-LADVCLEQ.mjs.map +1 -0
- package/dist/{chunk-2BJ3B4FR.mjs → chunk-NJBRKKLK.mjs} +46 -7
- package/dist/chunk-NJBRKKLK.mjs.map +1 -0
- package/dist/{chunk-6OAHCEDJ.mjs → chunk-QDUPSU5O.mjs} +5 -5
- package/dist/chunk-QDUPSU5O.mjs.map +1 -0
- package/dist/{chunk-H3XZTZ5K.mjs → chunk-RK2B5AOQ.mjs} +41 -29
- package/dist/chunk-RK2B5AOQ.mjs.map +1 -0
- package/dist/{chunk-L242CZ64.mjs → chunk-TIR7KHXL.mjs} +3 -3
- package/dist/chunk-TIR7KHXL.mjs.map +1 -0
- package/dist/{chunk-O5EQYHNC.mjs → chunk-ZOQHHFYA.mjs} +7 -4
- package/dist/chunk-ZOQHHFYA.mjs.map +1 -0
- package/dist/{chunk-EIS4SCQW.mjs → chunk-ZQTI4T2K.mjs} +231 -220
- package/dist/chunk-ZQTI4T2K.mjs.map +1 -0
- package/dist/config/env.d.mts +3 -0
- package/dist/config/env.d.ts +3 -0
- package/dist/config/env.js +12 -2
- package/dist/config/env.js.map +1 -1
- package/dist/config/env.mjs +1 -1
- package/dist/db/index.d.mts +3 -7
- package/dist/db/index.d.ts +3 -7
- package/dist/db/index.js +61 -12
- package/dist/db/index.js.map +1 -1
- package/dist/db/index.mjs +3 -3
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +14 -4
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.d.mts +2 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.js +62 -13
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.d.mts +4 -3
- package/dist/marketing/index.d.ts +4 -3
- package/dist/marketing/index.js +14 -4
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{email-template-passkey-change-F5Q2SXHD.mjs → passkey-changed-KEGNTIPE.mjs} +2 -2
- package/dist/passkey-changed-KEGNTIPE.mjs.map +1 -0
- package/dist/{email-template-reset-password-QTCQNXOD.mjs → reset-password-64VQEXBW.mjs} +2 -2
- package/dist/reset-password-64VQEXBW.mjs.map +1 -0
- package/dist/{schema-DzC5zdOq.d.mts → schema-BujGgvAy.d.mts} +35 -2
- package/dist/{schema-DzC5zdOq.d.ts → schema-BujGgvAy.d.ts} +35 -2
- package/dist/sessions/queries.js +61 -12
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/sessions/queries.mjs.map +1 -1
- package/dist/settings/queries.d.mts +11 -2
- package/dist/settings/queries.d.ts +11 -2
- package/dist/settings/queries.js +84 -13
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +41 -21
- package/dist/users/queries.d.ts +41 -21
- package/dist/users/queries.js +117 -23
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +57 -17
- package/dist/users/queries.mjs.map +1 -1
- package/dist/{email-template-verify-email-WZDCCAKK.mjs → verify-email-4KMNGDKN.mjs} +2 -2
- package/dist/verify-email-4KMNGDKN.mjs.map +1 -0
- package/lib/{auth-client.ts → auth/client.ts} +22 -2
- package/lib/push/client.ts +39 -0
- package/lib/security/activity-severity.ts +57 -0
- package/lib/{request-info.ts → utils/request-info.ts} +7 -3
- package/package.json +177 -75
- package/scripts/check-deps.mjs +68 -0
- package/components/dashboard/admin/adminActivityLogsTable.tsx +0 -323
- package/components/dashboard/admin/adminUserStatusCard.tsx +0 -57
- package/components/dashboard/admin/systemSettingsForm.tsx +0 -289
- package/dist/chunk-2BJ3B4FR.mjs.map +0 -1
- package/dist/chunk-653GF7OT.mjs.map +0 -1
- package/dist/chunk-6OAHCEDJ.mjs.map +0 -1
- package/dist/chunk-EIS4SCQW.mjs.map +0 -1
- package/dist/chunk-H3XZTZ5K.mjs.map +0 -1
- package/dist/chunk-HUEDEAY3.mjs.map +0 -1
- package/dist/chunk-K62JYJRR.mjs +0 -30
- package/dist/chunk-K62JYJRR.mjs.map +0 -1
- package/dist/chunk-L242CZ64.mjs.map +0 -1
- package/dist/chunk-NQELV53D.mjs.map +0 -1
- package/dist/chunk-O5EQYHNC.mjs.map +0 -1
- package/dist/chunk-TE5BEAQB.mjs.map +0 -1
- package/dist/email-template-passkey-change-F5Q2SXHD.mjs.map +0 -1
- package/dist/email-template-reset-password-QTCQNXOD.mjs.map +0 -1
- package/dist/email-template-verify-email-WZDCCAKK.mjs.map +0 -1
- /package/components/dashboard/{heartbeat.tsx → common/heartbeat.tsx} +0 -0
- /package/components/email/{email-template-reset-password.tsx → auth/reset-password.tsx} +0 -0
- /package/components/email/{email-template-verify-email.tsx → auth/verify-email.tsx} +0 -0
- /package/components/email/{email-template-welcome.tsx → auth/welcome.tsx} +0 -0
- /package/components/email/{email-template.tsx → layout/base-layout.tsx} +0 -0
- /package/components/email/{email-template-2.tsx → marketing/general-announcement.tsx} +0 -0
- /package/components/email/{email-template-banned.tsx → security/account-banned.tsx} +0 -0
- /package/components/email/{email-template-new-device.tsx → security/new-device-alert.tsx} +0 -0
- /package/components/email/{email-template-passkey-change.tsx → security/passkey-changed.tsx} +0 -0
- /package/lib/{maintenance.ts → config/maintenance.ts} +0 -0
- /package/lib/{cookie-consent.ts → security/cookie-consent.ts} +0 -0
- /package/lib/{cookie-names.ts → security/cookie-names.ts} +0 -0
- /package/lib/{device-fingerprint.ts → security/device-fingerprint.ts} +0 -0
- /package/lib/{formatters.ts → utils/formatters.ts} +0 -0
- /package/lib/{recalculate-columns.ts → utils/recalculate-columns.ts} +0 -0
package/dist/api/marketing.js
CHANGED
|
@@ -6,6 +6,9 @@ require('server-only');
|
|
|
6
6
|
var server = require('next/server');
|
|
7
7
|
var headers = require('next/headers');
|
|
8
8
|
var zod = require('zod');
|
|
9
|
+
var child_process = require('child_process');
|
|
10
|
+
var fs = require('fs');
|
|
11
|
+
var path = require('path');
|
|
9
12
|
var betterAuth = require('better-auth');
|
|
10
13
|
var drizzle = require('better-auth/adapters/drizzle');
|
|
11
14
|
var cuid2 = require('@paralleldrive/cuid2');
|
|
@@ -49,17 +52,22 @@ var __spreadValues = (a, b) => {
|
|
|
49
52
|
return a;
|
|
50
53
|
};
|
|
51
54
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
52
|
-
var __esm = (fn, res) => function __init() {
|
|
53
|
-
|
|
55
|
+
var __esm = (fn, res, err) => function __init() {
|
|
56
|
+
if (err) throw err[0];
|
|
57
|
+
try {
|
|
58
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
throw err = [e], e;
|
|
61
|
+
}
|
|
54
62
|
};
|
|
55
63
|
var __export = (target, all) => {
|
|
56
64
|
for (var name in all)
|
|
57
65
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
58
66
|
};
|
|
59
67
|
|
|
60
|
-
// components/email/
|
|
61
|
-
var
|
|
62
|
-
__export(
|
|
68
|
+
// components/email/security/passkey-changed.tsx
|
|
69
|
+
var passkey_changed_exports = {};
|
|
70
|
+
__export(passkey_changed_exports, {
|
|
63
71
|
EmailTemplatePasskeyChange: () => EmailTemplatePasskeyChange
|
|
64
72
|
});
|
|
65
73
|
function EmailTemplatePasskeyChange({
|
|
@@ -120,14 +128,14 @@ function EmailTemplatePasskeyChange({
|
|
|
120
128
|
] }) }) }) })
|
|
121
129
|
] });
|
|
122
130
|
}
|
|
123
|
-
var
|
|
124
|
-
"components/email/
|
|
131
|
+
var init_passkey_changed = __esm({
|
|
132
|
+
"components/email/security/passkey-changed.tsx"() {
|
|
125
133
|
}
|
|
126
134
|
});
|
|
127
135
|
|
|
128
|
-
// components/email/
|
|
129
|
-
var
|
|
130
|
-
__export(
|
|
136
|
+
// components/email/auth/reset-password.tsx
|
|
137
|
+
var reset_password_exports = {};
|
|
138
|
+
__export(reset_password_exports, {
|
|
131
139
|
EmailTemplateResetPassword: () => EmailTemplateResetPassword
|
|
132
140
|
});
|
|
133
141
|
function EmailTemplateResetPassword({ firstName, url }) {
|
|
@@ -164,14 +172,14 @@ function EmailTemplateResetPassword({ firstName, url }) {
|
|
|
164
172
|
] }) }) })
|
|
165
173
|
] });
|
|
166
174
|
}
|
|
167
|
-
var
|
|
168
|
-
"components/email/
|
|
175
|
+
var init_reset_password = __esm({
|
|
176
|
+
"components/email/auth/reset-password.tsx"() {
|
|
169
177
|
}
|
|
170
178
|
});
|
|
171
179
|
|
|
172
|
-
// components/email/
|
|
173
|
-
var
|
|
174
|
-
__export(
|
|
180
|
+
// components/email/auth/verify-email.tsx
|
|
181
|
+
var verify_email_exports = {};
|
|
182
|
+
__export(verify_email_exports, {
|
|
175
183
|
EmailTemplateVerifyEmail: () => EmailTemplateVerifyEmail
|
|
176
184
|
});
|
|
177
185
|
function EmailTemplateVerifyEmail({ firstName, url }) {
|
|
@@ -200,8 +208,8 @@ function EmailTemplateVerifyEmail({ firstName, url }) {
|
|
|
200
208
|
] }) }) }) })
|
|
201
209
|
] });
|
|
202
210
|
}
|
|
203
|
-
var
|
|
204
|
-
"components/email/
|
|
211
|
+
var init_verify_email = __esm({
|
|
212
|
+
"components/email/auth/verify-email.tsx"() {
|
|
205
213
|
}
|
|
206
214
|
});
|
|
207
215
|
|
|
@@ -225,7 +233,7 @@ __export(schema_exports, {
|
|
|
225
233
|
verifications: () => verifications
|
|
226
234
|
});
|
|
227
235
|
|
|
228
|
-
// lib/maintenance.ts
|
|
236
|
+
// lib/config/maintenance.ts
|
|
229
237
|
var DEFAULT_MAINTENANCE_EXEMPT_PATHS = [
|
|
230
238
|
"/",
|
|
231
239
|
"/features",
|
|
@@ -292,7 +300,10 @@ var sessions = pgCore.pgTable("session", {
|
|
|
292
300
|
// Set by better-auth's admin plugin while this session is an admin
|
|
293
301
|
// impersonating another user; holds the impersonating admin's user id.
|
|
294
302
|
impersonatedBy: pgCore.text("impersonatedBy")
|
|
295
|
-
})
|
|
303
|
+
}, (table) => [
|
|
304
|
+
// Read by userId on every login (session count), ban/delete and the admin sessions view.
|
|
305
|
+
pgCore.index("session_user_idx").on(table.userId)
|
|
306
|
+
]);
|
|
296
307
|
var accounts = pgCore.pgTable("account", {
|
|
297
308
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
298
309
|
accountId: pgCore.text("accountId").notNull(),
|
|
@@ -341,7 +352,10 @@ var verifications = pgCore.pgTable("verification", {
|
|
|
341
352
|
});
|
|
342
353
|
var activityLogs = pgCore.pgTable("activity_log", {
|
|
343
354
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
344
|
-
|
|
355
|
+
// SET NULL, not cascade: deleting an admin must not erase the audit trail of
|
|
356
|
+
// what they did. actorEmail keeps who it was once the user row is gone.
|
|
357
|
+
userId: pgCore.text("userId").references(() => users.id, { onDelete: "set null" }),
|
|
358
|
+
actorEmail: pgCore.text("actorEmail"),
|
|
345
359
|
action: ActivityActionEnum("action").notNull(),
|
|
346
360
|
description: pgCore.text("description").notNull(),
|
|
347
361
|
ipAddress: pgCore.text("ipAddress"),
|
|
@@ -357,7 +371,11 @@ var activityLogs = pgCore.pgTable("activity_log", {
|
|
|
357
371
|
country: pgCore.text("country"),
|
|
358
372
|
city: pgCore.text("city"),
|
|
359
373
|
createdAt: pgCore.timestamp("createdAt").notNull().defaultNow()
|
|
360
|
-
})
|
|
374
|
+
}, (table) => [
|
|
375
|
+
// Per-user history, and the admin log's newest-first ordering.
|
|
376
|
+
pgCore.index("activity_log_user_created_idx").on(table.userId, table.createdAt),
|
|
377
|
+
pgCore.index("activity_log_created_idx").on(table.createdAt)
|
|
378
|
+
]);
|
|
361
379
|
var deviceFingerprints = pgCore.pgTable("device_fingerprint", {
|
|
362
380
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
363
381
|
userId: pgCore.text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
@@ -472,7 +490,9 @@ var envSchema = zod.z.object({
|
|
|
472
490
|
RESEND_MARKETING_SEGMENT_ID: zod.z.string().default(""),
|
|
473
491
|
// Sender for every transactional email. Must be on a domain verified in
|
|
474
492
|
// your Resend account.
|
|
475
|
-
|
|
493
|
+
// Resend's shared sandbox sender: works without a verified domain but only
|
|
494
|
+
// delivers to your own Resend account email. Set your verified domain for real use.
|
|
495
|
+
EMAIL_FROM: zod.z.string().default("Acme <onboarding@resend.dev>"),
|
|
476
496
|
// Display name for this deployment — shown as the authenticator-app label
|
|
477
497
|
// (2FA issuer) and the passkey relying-party name. Consuming projects set
|
|
478
498
|
// this in their own .env; defaults to the template name.
|
|
@@ -482,6 +502,9 @@ var envSchema = zod.z.object({
|
|
|
482
502
|
// a comma-separated list and sends through Resend (needs RESEND_API_KEY).
|
|
483
503
|
FEEDBACK_DISCORD_WEBHOOK_URL: zod.z.string().default(""),
|
|
484
504
|
FEEDBACK_EMAIL: zod.z.string().default(""),
|
|
505
|
+
// Seconds between feedback messages per user (default 30, 0 = off). Read
|
|
506
|
+
// straight from process.env in lib/feedback/route.ts; listed here for docs.
|
|
507
|
+
FEEDBACK_COOLDOWN_SECONDS: zod.z.string().default("30"),
|
|
485
508
|
// Web Push (example, see lib/push.ts). Generate keys with
|
|
486
509
|
// `bunx web-push generate-vapid-keys`. Blank = the notifications card is hidden.
|
|
487
510
|
// The public key is also read in the browser as NEXT_PUBLIC_VAPID_PUBLIC_KEY.
|
|
@@ -498,7 +521,12 @@ var envSchema = zod.z.object({
|
|
|
498
521
|
DB_DRIVER: zod.z.enum(["pg", "neon"]).default("pg"),
|
|
499
522
|
// Only relevant when DB_DRIVER=pg — whether the target Postgres server has SSL
|
|
500
523
|
// enabled. Self-hosted Postgres (e.g. via Docker/Dokploy) typically does not.
|
|
501
|
-
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true")
|
|
524
|
+
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true"),
|
|
525
|
+
// With DATABASE_SSL=true the server certificate is verified. Set the CA (PEM,
|
|
526
|
+
// "\n" for newlines) for a self-signed or private CA; DATABASE_SSL_INSECURE=true
|
|
527
|
+
// skips verification (encrypts only). Both are read in config/pg-ssl.ts.
|
|
528
|
+
DATABASE_SSL_CA: zod.z.string().default(""),
|
|
529
|
+
DATABASE_SSL_INSECURE: zod.z.string().default("false")
|
|
502
530
|
});
|
|
503
531
|
|
|
504
532
|
// config/env.ts
|
|
@@ -512,24 +540,47 @@ if (!results.success) {
|
|
|
512
540
|
}
|
|
513
541
|
var config = results.data;
|
|
514
542
|
|
|
543
|
+
// config/pg-ssl.ts
|
|
544
|
+
function pgSslOptions() {
|
|
545
|
+
var _a;
|
|
546
|
+
if (process.env.DATABASE_SSL_INSECURE === "true") return { rejectUnauthorized: false };
|
|
547
|
+
const ca = (_a = process.env.DATABASE_SSL_CA) == null ? void 0 : _a.replace(/\\n/g, "\n");
|
|
548
|
+
return __spreadValues({ rejectUnauthorized: true }, ca ? { ca } : {});
|
|
549
|
+
}
|
|
550
|
+
|
|
515
551
|
// server/db/index.ts
|
|
516
552
|
var db;
|
|
517
553
|
if (config.DB_DRIVER === "pg") {
|
|
518
554
|
const pool = new pg.Pool({
|
|
519
555
|
connectionString: config.DATABASE_URL,
|
|
520
|
-
ssl: config.DATABASE_SSL ?
|
|
556
|
+
ssl: config.DATABASE_SSL ? pgSslOptions() : void 0,
|
|
557
|
+
// pg waits forever by default; a hung DB would otherwise freeze every request (proxy reads settings).
|
|
558
|
+
connectionTimeoutMillis: 5e3,
|
|
559
|
+
query_timeout: 15e3
|
|
560
|
+
// roomy enough for the 10k-row exports
|
|
521
561
|
});
|
|
522
562
|
db = nodePostgres.drizzle(pool, {
|
|
523
563
|
schema: schema_exports,
|
|
524
|
-
logger:
|
|
564
|
+
logger: process.env.NODE_ENV === "development"
|
|
525
565
|
});
|
|
526
566
|
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
567
|
} else {
|
|
532
|
-
|
|
568
|
+
serverless.neonConfig.fetchFunction = (url, init) => fetch(url, __spreadProps(__spreadValues({}, init), { signal: AbortSignal.timeout(15e3) }));
|
|
569
|
+
const sql6 = serverless.neon(config.DATABASE_URL);
|
|
570
|
+
db = neonHttp.drizzle(sql6, { schema: schema_exports, logger: process.env.NODE_ENV === "development" });
|
|
571
|
+
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// node_modules/@better-auth/utils/dist/bytes.mjs
|
|
575
|
+
function toBufferSource(data) {
|
|
576
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
577
|
+
if (!ArrayBuffer.isView(data)) return data;
|
|
578
|
+
if (data.buffer instanceof ArrayBuffer) return data;
|
|
579
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
|
|
580
|
+
}
|
|
581
|
+
function toUint8Array(data) {
|
|
582
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
583
|
+
return new Uint8Array(data);
|
|
533
584
|
}
|
|
534
585
|
|
|
535
586
|
// node_modules/@better-auth/utils/dist/base32.mjs
|
|
@@ -538,9 +589,7 @@ function getAlphabet(hex2) {
|
|
|
538
589
|
}
|
|
539
590
|
function createDecodeMap(alphabet) {
|
|
540
591
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
541
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
542
|
-
decodeMap.set(alphabet[i], i);
|
|
543
|
-
}
|
|
592
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
544
593
|
return decodeMap;
|
|
545
594
|
}
|
|
546
595
|
function base32Encode(data, alphabet, padding) {
|
|
@@ -555,9 +604,7 @@ function base32Encode(data, alphabet, padding) {
|
|
|
555
604
|
result += alphabet[buffer >> shift & 31];
|
|
556
605
|
}
|
|
557
606
|
}
|
|
558
|
-
if (shift > 0)
|
|
559
|
-
result += alphabet[buffer << 5 - shift & 31];
|
|
560
|
-
}
|
|
607
|
+
if (shift > 0) result += alphabet[buffer << 5 - shift & 31];
|
|
561
608
|
if (padding) {
|
|
562
609
|
const padCount = (8 - result.length % 8) % 8;
|
|
563
610
|
result += "=".repeat(padCount);
|
|
@@ -570,12 +617,9 @@ function base32Decode(data, alphabet) {
|
|
|
570
617
|
let buffer = 0;
|
|
571
618
|
let bitsCollected = 0;
|
|
572
619
|
for (const char of data) {
|
|
573
|
-
if (char === "=")
|
|
574
|
-
break;
|
|
620
|
+
if (char === "=") break;
|
|
575
621
|
const value = decodeMap.get(char);
|
|
576
|
-
if (value === void 0) {
|
|
577
|
-
throw new Error(`Invalid Base32 character: ${char}`);
|
|
578
|
-
}
|
|
622
|
+
if (value === void 0) throw new Error(`Invalid Base32 character: ${char}`);
|
|
579
623
|
buffer = buffer << 5 | value;
|
|
580
624
|
bitsCollected += 5;
|
|
581
625
|
while (bitsCollected >= 8) {
|
|
@@ -587,68 +631,34 @@ function base32Decode(data, alphabet) {
|
|
|
587
631
|
}
|
|
588
632
|
var base32 = {
|
|
589
633
|
/**
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
634
|
+
* Encodes data into a Base32 string.
|
|
635
|
+
* @param data - The data to encode (ArrayBuffer, number-based TypedArray, or string).
|
|
636
|
+
* @param options - Encoding options.
|
|
637
|
+
* @returns The Base32 encoded string.
|
|
638
|
+
*/
|
|
595
639
|
encode(data, options = {}) {
|
|
596
640
|
var _a;
|
|
597
641
|
const alphabet = getAlphabet();
|
|
598
|
-
|
|
599
|
-
return base32Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
642
|
+
return base32Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
600
643
|
},
|
|
601
644
|
/**
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
645
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
646
|
+
* @param data - The Base32 encoded string or ArrayBuffer/TypedArray.
|
|
647
|
+
* @returns The decoded Uint8Array.
|
|
648
|
+
*/
|
|
606
649
|
decode(data) {
|
|
607
|
-
if (typeof data !== "string")
|
|
608
|
-
data = new TextDecoder().decode(data);
|
|
609
|
-
}
|
|
650
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
610
651
|
const alphabet = getAlphabet();
|
|
611
652
|
return base32Decode(data, alphabet);
|
|
612
653
|
}
|
|
613
654
|
};
|
|
614
655
|
|
|
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
|
-
};
|
|
656
|
+
// node_modules/@better-auth/utils/dist/index.mjs
|
|
657
|
+
function getWebcryptoSubtle() {
|
|
658
|
+
const cr = typeof globalThis !== "undefined" && globalThis.crypto;
|
|
659
|
+
if (cr && typeof cr.subtle === "object" && cr.subtle != null) return cr.subtle;
|
|
660
|
+
throw new Error("crypto.subtle must be defined");
|
|
661
|
+
}
|
|
652
662
|
|
|
653
663
|
// node_modules/@better-auth/utils/dist/base64.mjs
|
|
654
664
|
function getAlphabet2(urlSafe) {
|
|
@@ -666,9 +676,7 @@ function base64Encode(data, alphabet, padding) {
|
|
|
666
676
|
result += alphabet[buffer >> shift & 63];
|
|
667
677
|
}
|
|
668
678
|
}
|
|
669
|
-
if (shift > 0)
|
|
670
|
-
result += alphabet[buffer << 6 - shift & 63];
|
|
671
|
-
}
|
|
679
|
+
if (shift > 0) result += alphabet[buffer << 6 - shift & 63];
|
|
672
680
|
if (padding) {
|
|
673
681
|
const padCount = (4 - result.length % 4) % 4;
|
|
674
682
|
result += "=".repeat(padCount);
|
|
@@ -677,19 +685,14 @@ function base64Encode(data, alphabet, padding) {
|
|
|
677
685
|
}
|
|
678
686
|
function base64Decode(data, alphabet) {
|
|
679
687
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
680
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
681
|
-
decodeMap.set(alphabet[i], i);
|
|
682
|
-
}
|
|
688
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
683
689
|
const result = [];
|
|
684
690
|
let buffer = 0;
|
|
685
691
|
let bitsCollected = 0;
|
|
686
692
|
for (const char of data) {
|
|
687
|
-
if (char === "=")
|
|
688
|
-
break;
|
|
693
|
+
if (char === "=") break;
|
|
689
694
|
const value = decodeMap.get(char);
|
|
690
|
-
if (value === void 0) {
|
|
691
|
-
throw new Error(`Invalid Base64 character: ${char}`);
|
|
692
|
-
}
|
|
695
|
+
if (value === void 0) throw new Error(`Invalid Base64 character: ${char}`);
|
|
693
696
|
buffer = buffer << 6 | value;
|
|
694
697
|
bitsCollected += 6;
|
|
695
698
|
if (bitsCollected >= 8) {
|
|
@@ -703,15 +706,11 @@ var base64 = {
|
|
|
703
706
|
encode(data, options = {}) {
|
|
704
707
|
var _a;
|
|
705
708
|
const alphabet = getAlphabet2(false);
|
|
706
|
-
|
|
707
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
709
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
708
710
|
},
|
|
709
711
|
decode(data) {
|
|
710
|
-
if (typeof data !== "string")
|
|
711
|
-
|
|
712
|
-
}
|
|
713
|
-
const urlSafe = data.includes("-") || data.includes("_");
|
|
714
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
712
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
713
|
+
const alphabet = getAlphabet2(data.includes("-") || data.includes("_"));
|
|
715
714
|
return base64Decode(data, alphabet);
|
|
716
715
|
}
|
|
717
716
|
};
|
|
@@ -719,152 +718,142 @@ var base64Url = {
|
|
|
719
718
|
encode(data, options = {}) {
|
|
720
719
|
var _a;
|
|
721
720
|
const alphabet = getAlphabet2(true);
|
|
722
|
-
|
|
723
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
721
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
724
722
|
},
|
|
725
723
|
decode(data) {
|
|
726
|
-
|
|
727
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
728
|
-
return base64Decode(data, alphabet);
|
|
724
|
+
return base64Decode(data, getAlphabet2(data.includes("-") || data.includes("_")));
|
|
729
725
|
}
|
|
730
726
|
};
|
|
731
727
|
|
|
732
|
-
// node_modules/@
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
728
|
+
// node_modules/@noble/hashes/utils.js
|
|
729
|
+
var hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
730
|
+
// @ts-ignore
|
|
731
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
732
|
+
))();
|
|
733
|
+
function asciiToBase16(ch) {
|
|
734
|
+
return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
|
|
735
|
+
}
|
|
736
|
+
function hexToBytes(hex2) {
|
|
737
|
+
if (typeof hex2 !== "string")
|
|
738
|
+
throw new TypeError("hex string expected, got " + typeof hex2);
|
|
739
|
+
if (hasHexBuiltin) {
|
|
740
|
+
try {
|
|
741
|
+
return Uint8Array.fromHex(hex2);
|
|
742
|
+
} catch (error) {
|
|
743
|
+
if (error instanceof SyntaxError)
|
|
744
|
+
throw new RangeError(error.message);
|
|
745
|
+
throw error;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
const hl = hex2.length;
|
|
749
|
+
const al = hl / 2;
|
|
750
|
+
if (hl % 2)
|
|
751
|
+
throw new RangeError("hex string expected, got unpadded hex of length " + hl);
|
|
752
|
+
const array = new Uint8Array(al);
|
|
753
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
754
|
+
const n1 = asciiToBase16(hex2.charCodeAt(hi));
|
|
755
|
+
const n2 = asciiToBase16(hex2.charCodeAt(hi + 1));
|
|
756
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
757
|
+
const char = hex2[hi] + hex2[hi + 1];
|
|
758
|
+
throw new RangeError('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
759
|
+
}
|
|
760
|
+
array[ai] = n1 * 16 + n2;
|
|
761
|
+
}
|
|
762
|
+
return array;
|
|
738
763
|
}
|
|
739
764
|
|
|
765
|
+
// node_modules/@better-auth/utils/dist/hex.mjs
|
|
766
|
+
var toBytes = (data) => hexToBytes(data);
|
|
767
|
+
var hex = {
|
|
768
|
+
encode: (data) => {
|
|
769
|
+
const buffer = toUint8Array(data);
|
|
770
|
+
if (buffer.byteLength === 0) return "";
|
|
771
|
+
let result = "";
|
|
772
|
+
for (const byte of buffer) result += byte.toString(16).padStart(2, "0");
|
|
773
|
+
return result;
|
|
774
|
+
},
|
|
775
|
+
decode: (data) => {
|
|
776
|
+
if (!data) return "";
|
|
777
|
+
if (typeof data === "string") return new TextDecoder().decode(toBytes(data));
|
|
778
|
+
return new TextDecoder().decode(data);
|
|
779
|
+
},
|
|
780
|
+
toBytes
|
|
781
|
+
};
|
|
782
|
+
|
|
740
783
|
// node_modules/@better-auth/utils/dist/hmac.mjs
|
|
741
784
|
var createHMAC = (algorithm = "SHA-256", encoding = "none") => {
|
|
742
|
-
const
|
|
785
|
+
const hmac2 = {
|
|
743
786
|
importKey: async (key, keyUsage) => {
|
|
744
|
-
return getWebcryptoSubtle().importKey(
|
|
745
|
-
"
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
false,
|
|
749
|
-
[keyUsage]
|
|
750
|
-
);
|
|
787
|
+
return getWebcryptoSubtle().importKey("raw", toBufferSource(key), {
|
|
788
|
+
name: "HMAC",
|
|
789
|
+
hash: { name: algorithm }
|
|
790
|
+
}, false, [keyUsage]);
|
|
751
791
|
},
|
|
752
792
|
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
|
-
}
|
|
793
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "sign");
|
|
794
|
+
const signature = await getWebcryptoSubtle().sign("HMAC", hmacKey, toBufferSource(data));
|
|
795
|
+
if (encoding === "hex") return hex.encode(signature);
|
|
796
|
+
if (encoding === "base64") return base64.encode(signature);
|
|
797
|
+
if (encoding === "base64url" || encoding === "base64urlnopad") return base64Url.encode(signature, { padding: encoding !== "base64urlnopad" });
|
|
769
798
|
return signature;
|
|
770
799
|
},
|
|
771
800
|
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
|
-
);
|
|
801
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "verify");
|
|
802
|
+
if (encoding === "hex") signature = typeof signature === "string" ? hex.toBytes(signature) : signature;
|
|
803
|
+
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") signature = await base64.decode(signature);
|
|
804
|
+
return getWebcryptoSubtle().verify("HMAC", hmacKey, toBufferSource(signature), toBufferSource(data));
|
|
787
805
|
}
|
|
788
806
|
};
|
|
789
|
-
return
|
|
807
|
+
return hmac2;
|
|
790
808
|
};
|
|
791
809
|
|
|
792
810
|
// node_modules/@better-auth/utils/dist/otp.mjs
|
|
793
811
|
var defaultPeriod = 30;
|
|
794
812
|
var defaultDigits = 6;
|
|
813
|
+
var hmac = createHMAC("SHA-1");
|
|
795
814
|
function constantTimeEqualOTP(input, expected) {
|
|
796
815
|
let difference = input.length ^ expected.length;
|
|
797
|
-
for (let i = 0; i < expected.length; i++)
|
|
798
|
-
difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
799
|
-
}
|
|
816
|
+
for (let i = 0; i < expected.length; i++) difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
800
817
|
return difference === 0;
|
|
801
818
|
}
|
|
802
|
-
async function generateHOTP(
|
|
803
|
-
counter,
|
|
804
|
-
digits,
|
|
805
|
-
hash = "SHA-1"
|
|
806
|
-
}) {
|
|
819
|
+
async function generateHOTP(key, { counter, digits }) {
|
|
807
820
|
const _digits = digits != null ? digits : defaultDigits;
|
|
808
|
-
if (_digits < 1 || _digits > 8)
|
|
809
|
-
|
|
810
|
-
}
|
|
811
|
-
const buffer = new ArrayBuffer(8);
|
|
821
|
+
if (_digits < 1 || _digits > 8) throw new TypeError("Digits must be between 1 and 8");
|
|
822
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
812
823
|
new DataView(buffer).setBigUint64(0, BigInt(counter), false);
|
|
813
824
|
const bytes = new Uint8Array(buffer);
|
|
814
|
-
const
|
|
825
|
+
const signature = await hmac.sign(key, bytes);
|
|
826
|
+
const hmacResult = new Uint8Array(signature);
|
|
815
827
|
const offset = hmacResult[hmacResult.length - 1] & 15;
|
|
816
|
-
|
|
817
|
-
const otp = truncated % 10 ** _digits;
|
|
818
|
-
return otp.toString().padStart(_digits, "0");
|
|
828
|
+
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
829
|
}
|
|
820
|
-
async function generateTOTP(
|
|
830
|
+
async function generateTOTP(key, options) {
|
|
821
831
|
var _a, _b;
|
|
822
832
|
const digits = (_a = options == null ? void 0 : options.digits) != null ? _a : defaultDigits;
|
|
823
|
-
const
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
833
|
+
const milliseconds = ((_b = options == null ? void 0 : options.period) != null ? _b : defaultPeriod) * 1e3;
|
|
834
|
+
return await generateHOTP(key, {
|
|
835
|
+
counter: Math.floor(Date.now() / milliseconds),
|
|
836
|
+
digits
|
|
837
|
+
});
|
|
827
838
|
}
|
|
828
|
-
async function verifyTOTP(otp, {
|
|
829
|
-
window = 1,
|
|
830
|
-
digits = defaultDigits,
|
|
831
|
-
secret,
|
|
832
|
-
period = defaultPeriod
|
|
833
|
-
}) {
|
|
839
|
+
async function verifyTOTP(otp, { window = 1, digits = defaultDigits, key, period = defaultPeriod }) {
|
|
834
840
|
const milliseconds = period * 1e3;
|
|
835
841
|
const counter = Math.floor(Date.now() / milliseconds);
|
|
836
842
|
let matched = false;
|
|
837
|
-
for (let i = -window; i <= window; i++) {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
});
|
|
842
|
-
matched = constantTimeEqualOTP(otp, generatedOTP) || matched;
|
|
843
|
-
}
|
|
843
|
+
for (let i = -window; i <= window; i++) matched = constantTimeEqualOTP(otp, await generateHOTP(key, {
|
|
844
|
+
counter: counter + i,
|
|
845
|
+
digits
|
|
846
|
+
})) || matched;
|
|
844
847
|
return matched;
|
|
845
848
|
}
|
|
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}`;
|
|
849
|
+
function generateQRCode({ issuer, account, secret, digits = defaultDigits, period = defaultPeriod }) {
|
|
850
|
+
const baseURI = `otpauth://totp/${encodeURIComponent(issuer)}:${encodeURIComponent(account)}`;
|
|
856
851
|
const params = new URLSearchParams({
|
|
857
|
-
secret: base32.encode(secret, {
|
|
858
|
-
padding: false
|
|
859
|
-
}),
|
|
852
|
+
secret: base32.encode(secret, { padding: false }),
|
|
860
853
|
issuer
|
|
861
854
|
});
|
|
862
|
-
if (digits !== void 0)
|
|
863
|
-
|
|
864
|
-
}
|
|
865
|
-
if (period !== void 0) {
|
|
866
|
-
params.set("period", period.toString());
|
|
867
|
-
}
|
|
855
|
+
if (digits !== void 0) params.set("digits", digits.toString());
|
|
856
|
+
if (period !== void 0) params.set("period", period.toString());
|
|
868
857
|
return `${baseURI}?${params.toString()}`;
|
|
869
858
|
}
|
|
870
859
|
var createOTP = (secret, opts) => {
|
|
@@ -872,14 +861,38 @@ var createOTP = (secret, opts) => {
|
|
|
872
861
|
const digits = (_a = void 0 ) != null ? _a : defaultDigits;
|
|
873
862
|
const period = (_b = void 0 ) != null ? _b : defaultPeriod;
|
|
874
863
|
return {
|
|
875
|
-
hotp: (counter) =>
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
864
|
+
hotp: async (counter) => {
|
|
865
|
+
return generateHOTP(await hmac.importKey(secret, "sign"), {
|
|
866
|
+
counter,
|
|
867
|
+
digits
|
|
868
|
+
});
|
|
869
|
+
},
|
|
870
|
+
totp: async () => {
|
|
871
|
+
return generateTOTP(await hmac.importKey(secret, "sign"), {
|
|
872
|
+
digits,
|
|
873
|
+
period
|
|
874
|
+
});
|
|
875
|
+
},
|
|
876
|
+
verify: async (otp, options) => {
|
|
877
|
+
return verifyTOTP(otp, __spreadValues({
|
|
878
|
+
key: await hmac.importKey(secret, "sign"),
|
|
879
|
+
digits,
|
|
880
|
+
period
|
|
881
|
+
}, options));
|
|
882
|
+
},
|
|
883
|
+
url: (issuer, account) => {
|
|
884
|
+
return generateQRCode({
|
|
885
|
+
issuer,
|
|
886
|
+
account,
|
|
887
|
+
secret,
|
|
888
|
+
digits,
|
|
889
|
+
period
|
|
890
|
+
});
|
|
891
|
+
}
|
|
879
892
|
};
|
|
880
893
|
};
|
|
881
894
|
|
|
882
|
-
// lib/two-factor.ts
|
|
895
|
+
// lib/auth/two-factor.ts
|
|
883
896
|
var CHALLENGED_PATHS = ["/callback/:id", "/one-tap/callback"];
|
|
884
897
|
var CODE_REQUIRED_PATHS = ["/two-factor/disable", "/two-factor/generate-backup-codes"];
|
|
885
898
|
function twoFactorPlugins(baseURL, { issuer, passwordless = false, challengeAfterOAuth = false }) {
|
|
@@ -952,6 +965,8 @@ async function logActivity({
|
|
|
952
965
|
try {
|
|
953
966
|
await db.insert(activityLogs).values({
|
|
954
967
|
userId,
|
|
968
|
+
// Snapshot the email at write time; survives deletion of the user row.
|
|
969
|
+
actorEmail: drizzleOrm.sql`(select "email" from "user" where "id" = ${userId})`,
|
|
955
970
|
action,
|
|
956
971
|
description,
|
|
957
972
|
ipAddress: ipAddress || null,
|
|
@@ -972,7 +987,7 @@ var countryNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
|
972
987
|
function getClientIp(headers3) {
|
|
973
988
|
var _a;
|
|
974
989
|
const forwardedFor = headers3 == null ? void 0 : headers3.get("x-forwarded-for");
|
|
975
|
-
if (forwardedFor) return forwardedFor.split(",")
|
|
990
|
+
if (forwardedFor) return forwardedFor.split(",").at(-1).trim();
|
|
976
991
|
return (_a = headers3 == null ? void 0 : headers3.get("x-real-ip")) != null ? _a : null;
|
|
977
992
|
}
|
|
978
993
|
function parseUserAgent(userAgent) {
|
|
@@ -1011,11 +1026,21 @@ function formatLocation({ country, city }) {
|
|
|
1011
1026
|
return [city, country].filter(Boolean).join(", ");
|
|
1012
1027
|
}
|
|
1013
1028
|
|
|
1014
|
-
// lib/cookie-names.ts
|
|
1029
|
+
// lib/security/cookie-names.ts
|
|
1015
1030
|
var LOGIN_REFERRER_COOKIE = "login_referrer";
|
|
1016
1031
|
var DEVICE_FINGERPRINT_HEADER = "x-device-fingerprint";
|
|
1017
1032
|
|
|
1018
|
-
// lib/auth-
|
|
1033
|
+
// lib/auth/base-url.ts
|
|
1034
|
+
function getBaseUrl() {
|
|
1035
|
+
const url = process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
|
|
1036
|
+
return url.replace(/\/+$/, "");
|
|
1037
|
+
}
|
|
1038
|
+
function otherActiveAdminExists(excludeIds) {
|
|
1039
|
+
const ids = drizzleOrm.sql.join(excludeIds.map((id) => drizzleOrm.sql`${id}`), drizzleOrm.sql`, `);
|
|
1040
|
+
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`;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
// lib/auth/throttle-limits.ts
|
|
1019
1044
|
var WINDOW_MS = 15 * 60 * 1e3;
|
|
1020
1045
|
var MAX = 10;
|
|
1021
1046
|
var MAX_IP = MAX * 3;
|
|
@@ -1026,7 +1051,7 @@ function isOverLimit(row, now, max = MAX) {
|
|
|
1026
1051
|
return row.count >= max;
|
|
1027
1052
|
}
|
|
1028
1053
|
|
|
1029
|
-
// lib/auth
|
|
1054
|
+
// lib/auth/throttle.ts
|
|
1030
1055
|
async function isDeviceThrottled(fingerprint, max) {
|
|
1031
1056
|
try {
|
|
1032
1057
|
const [row] = await db.select({ count: authThrottle.count, windowStart: authThrottle.windowStart }).from(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint)).limit(1);
|
|
@@ -1050,8 +1075,10 @@ async function recordDeviceAttempt(fingerprint, meta) {
|
|
|
1050
1075
|
await db.insert(authThrottle).values(__spreadValues({ fingerprint, count: 1, windowStart: now }, seen)).onConflictDoUpdate({
|
|
1051
1076
|
target: authThrottle.fingerprint,
|
|
1052
1077
|
set: __spreadValues({
|
|
1053
|
-
|
|
1054
|
-
|
|
1078
|
+
// ISO strings, not Dates: pg sends a raw Date as server-local time, which a
|
|
1079
|
+
// tz-less `timestamp` column (stored as UTC) misreads on any non-UTC host.
|
|
1080
|
+
count: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then 1 else ${authThrottle.count} + 1 end`,
|
|
1081
|
+
windowStart: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then ${now.toISOString()} else ${authThrottle.windowStart} end`
|
|
1055
1082
|
}, seen)
|
|
1056
1083
|
});
|
|
1057
1084
|
} catch (error) {
|
|
@@ -1070,15 +1097,9 @@ async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
|
1070
1097
|
console.error("auth-throttle prune failed", error);
|
|
1071
1098
|
}
|
|
1072
1099
|
}
|
|
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
1100
|
var SETTINGS_ROW_ID = "default";
|
|
1081
1101
|
var CACHE_TTL_MS = 1e4;
|
|
1102
|
+
var FAILURE_CACHE_TTL_MS = 5e3;
|
|
1082
1103
|
var cached = null;
|
|
1083
1104
|
function fallbackSettings() {
|
|
1084
1105
|
return {
|
|
@@ -1121,7 +1142,9 @@ async function getSystemSettings() {
|
|
|
1121
1142
|
return value;
|
|
1122
1143
|
} catch (error) {
|
|
1123
1144
|
console.error("Failed to load system settings, failing open:", error);
|
|
1124
|
-
|
|
1145
|
+
const value = fallbackSettings();
|
|
1146
|
+
cached = { value, expiresAt: now + FAILURE_CACHE_TTL_MS };
|
|
1147
|
+
return value;
|
|
1125
1148
|
}
|
|
1126
1149
|
}
|
|
1127
1150
|
async function getEffectiveAuthFlags() {
|
|
@@ -1152,6 +1175,21 @@ async function getBroadcastResend() {
|
|
|
1152
1175
|
}
|
|
1153
1176
|
|
|
1154
1177
|
// server/auth.ts
|
|
1178
|
+
function checkDepsOnce() {
|
|
1179
|
+
const flag = globalThis;
|
|
1180
|
+
if (process.env.NODE_ENV !== "development" || flag.__xkDepsChecked) return;
|
|
1181
|
+
flag.__xkDepsChecked = true;
|
|
1182
|
+
const script = path.join(
|
|
1183
|
+
/*turbopackIgnore: true*/
|
|
1184
|
+
process.cwd(),
|
|
1185
|
+
"node_modules/@xk2800/nextjs-template/scripts/check-deps.mjs"
|
|
1186
|
+
);
|
|
1187
|
+
if (!fs.existsSync(script)) return;
|
|
1188
|
+
child_process.execFile(process.execPath, [script], (_err, stdout) => {
|
|
1189
|
+
if (stdout == null ? void 0 : stdout.trim()) console.log(stdout);
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
checkDepsOnce();
|
|
1155
1193
|
async function logFailedLogin(ctx, log) {
|
|
1156
1194
|
var _a, _b, _c;
|
|
1157
1195
|
try {
|
|
@@ -1186,7 +1224,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1186
1224
|
userAgent: (_b = (_a = ctx.headers) == null ? void 0 : _a.get("user-agent")) != null ? _b : null
|
|
1187
1225
|
});
|
|
1188
1226
|
if (!config.RESEND_API_KEY) return;
|
|
1189
|
-
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (
|
|
1227
|
+
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (init_passkey_changed(), passkey_changed_exports));
|
|
1190
1228
|
await (await getResend()).emails.send({
|
|
1191
1229
|
from: EMAIL_FROM,
|
|
1192
1230
|
to: [user.email],
|
|
@@ -1198,7 +1236,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1198
1236
|
location: formatLocation(lookupGeoLocation(ip)),
|
|
1199
1237
|
ipAddress: ip || "Unknown",
|
|
1200
1238
|
when: (/* @__PURE__ */ new Date()).toUTCString(),
|
|
1201
|
-
manageUrl: `${
|
|
1239
|
+
manageUrl: `${getBaseUrl()}/dashboard/settings`
|
|
1202
1240
|
})
|
|
1203
1241
|
});
|
|
1204
1242
|
} catch (error) {
|
|
@@ -1249,6 +1287,15 @@ async function packageSessionCreated(log, ...[session, context]) {
|
|
|
1249
1287
|
console.error("Failed to log login activity", error);
|
|
1250
1288
|
}
|
|
1251
1289
|
}
|
|
1290
|
+
async function promoteFirstAdmin(user) {
|
|
1291
|
+
var _a;
|
|
1292
|
+
const adminEmail = (_a = process.env.ADMIN_EMAIL) == null ? void 0 : _a.trim().toLowerCase();
|
|
1293
|
+
if (!adminEmail || !user.emailVerified || user.email.toLowerCase() !== adminEmail) return;
|
|
1294
|
+
const [existing] = await db.select({ id: users.id }).from(users).where(drizzleOrm.eq(users.role, "admin")).limit(1);
|
|
1295
|
+
if (existing) return;
|
|
1296
|
+
await db.update(users).set({ role: "admin" }).where(drizzleOrm.eq(users.id, user.id));
|
|
1297
|
+
user.role = "admin";
|
|
1298
|
+
}
|
|
1252
1299
|
function createAuth(overrides = {}) {
|
|
1253
1300
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1254
1301
|
const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
|
|
@@ -1264,7 +1311,7 @@ function createAuth(overrides = {}) {
|
|
|
1264
1311
|
"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
1312
|
);
|
|
1266
1313
|
}
|
|
1267
|
-
const baseURL =
|
|
1314
|
+
const baseURL = getBaseUrl();
|
|
1268
1315
|
const log = (_a = overrides.logActivity) != null ? _a : logActivity;
|
|
1269
1316
|
const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
|
|
1270
1317
|
issuer: config.APP_NAME,
|
|
@@ -1312,7 +1359,7 @@ function createAuth(overrides = {}) {
|
|
|
1312
1359
|
// callbackURL) — see app/(auth)/forgot-password and reset-password for
|
|
1313
1360
|
// the pages this points at.
|
|
1314
1361
|
async sendResetPassword({ user, url }) {
|
|
1315
|
-
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (
|
|
1362
|
+
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (init_reset_password(), reset_password_exports));
|
|
1316
1363
|
await (await getResend()).emails.send({
|
|
1317
1364
|
from: EMAIL_FROM,
|
|
1318
1365
|
to: [user.email],
|
|
@@ -1328,8 +1375,11 @@ function createAuth(overrides = {}) {
|
|
|
1328
1375
|
// callback that flips users.emailVerified on click.
|
|
1329
1376
|
emailVerification: {
|
|
1330
1377
|
autoSignInAfterVerification: true,
|
|
1378
|
+
async afterEmailVerification(user) {
|
|
1379
|
+
await promoteFirstAdmin(user);
|
|
1380
|
+
},
|
|
1331
1381
|
async sendVerificationEmail({ user, url }) {
|
|
1332
|
-
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (
|
|
1382
|
+
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (init_verify_email(), verify_email_exports));
|
|
1333
1383
|
await (await getResend()).emails.send({
|
|
1334
1384
|
from: EMAIL_FROM,
|
|
1335
1385
|
to: [user.email],
|
|
@@ -1371,6 +1421,7 @@ function createAuth(overrides = {}) {
|
|
|
1371
1421
|
create: {
|
|
1372
1422
|
async after(user, context) {
|
|
1373
1423
|
var _a2, _b2, _c2, _d2;
|
|
1424
|
+
await promoteFirstAdmin(user);
|
|
1374
1425
|
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
1426
|
}
|
|
1376
1427
|
}
|
|
@@ -1394,7 +1445,7 @@ function createAuth(overrides = {}) {
|
|
|
1394
1445
|
// available together.
|
|
1395
1446
|
hooks: {
|
|
1396
1447
|
before: api.createAuthMiddleware(async (ctx) => {
|
|
1397
|
-
var _a2, _b2, _c2, _d2;
|
|
1448
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
1398
1449
|
if (ctx.path === "/sign-in/email" || ctx.path === "/sign-up/email") {
|
|
1399
1450
|
const fingerprint = (_a2 = ctx.headers) == null ? void 0 : _a2.get(DEVICE_FINGERPRINT_HEADER);
|
|
1400
1451
|
const ip = getClientIp(ctx.headers);
|
|
@@ -1428,6 +1479,9 @@ function createAuth(overrides = {}) {
|
|
|
1428
1479
|
}
|
|
1429
1480
|
return;
|
|
1430
1481
|
}
|
|
1482
|
+
if (ctx.request && ((_c2 = ctx.path) == null ? void 0 : _c2.startsWith("/admin/")) && ctx.path !== "/admin/impersonate-user" && ctx.path !== "/admin/stop-impersonating") {
|
|
1483
|
+
throw new api.APIError("FORBIDDEN", { message: "Use the dashboard to manage users." });
|
|
1484
|
+
}
|
|
1431
1485
|
if (ctx.path === "/admin/impersonate-user" && overrides.impersonation === false) {
|
|
1432
1486
|
throw new api.APIError("FORBIDDEN", { message: "Impersonation is turned off." });
|
|
1433
1487
|
}
|
|
@@ -1438,8 +1492,8 @@ function createAuth(overrides = {}) {
|
|
|
1438
1492
|
throw new api.APIError("FORBIDDEN", { message: "Stop impersonating before deleting an account." });
|
|
1439
1493
|
}
|
|
1440
1494
|
if (current2.user.role === "admin") {
|
|
1441
|
-
const [
|
|
1442
|
-
if (
|
|
1495
|
+
const [other] = await db.select({ n: drizzleOrm.sql`1` }).from(users).where(otherActiveAdminExists([current2.user.id])).limit(1);
|
|
1496
|
+
if (!other) {
|
|
1443
1497
|
throw new api.APIError("FORBIDDEN", { message: "You're the only admin. Promote another user to admin first." });
|
|
1444
1498
|
}
|
|
1445
1499
|
}
|
|
@@ -1452,7 +1506,7 @@ function createAuth(overrides = {}) {
|
|
|
1452
1506
|
await log({
|
|
1453
1507
|
userId: current.session.impersonatedBy,
|
|
1454
1508
|
action: "impersonation_stopped",
|
|
1455
|
-
description: `Admin stopped impersonating ${(
|
|
1509
|
+
description: `Admin stopped impersonating ${(_e2 = (_d2 = target[0]) == null ? void 0 : _d2.email) != null ? _e2 : current.session.userId}`,
|
|
1456
1510
|
metadata: { impersonatedUserId: current.session.userId }
|
|
1457
1511
|
});
|
|
1458
1512
|
}
|
|
@@ -1488,8 +1542,6 @@ function createAuth(overrides = {}) {
|
|
|
1488
1542
|
if (failed) {
|
|
1489
1543
|
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
1490
1544
|
await logFailedLogin(ctx, log);
|
|
1491
|
-
} else {
|
|
1492
|
-
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
1493
1545
|
}
|
|
1494
1546
|
})
|
|
1495
1547
|
},
|
|
@@ -1570,14 +1622,25 @@ var auth = new Proxy({}, {
|
|
|
1570
1622
|
return Reflect.getOwnPropertyDescriptor(getDefaultAuth(), prop);
|
|
1571
1623
|
}
|
|
1572
1624
|
});
|
|
1625
|
+
|
|
1626
|
+
// lib/auth/pure.ts
|
|
1627
|
+
function hasRole(userRole, requiredRole) {
|
|
1628
|
+
if (!userRole) return false;
|
|
1629
|
+
{
|
|
1630
|
+
return userRole === "admin";
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
// lib/auth/helpers.ts
|
|
1573
1635
|
var getCurrentSession = react.cache(async () => {
|
|
1574
1636
|
const session = await auth.api.getSession({
|
|
1575
|
-
headers: await headers.headers()
|
|
1637
|
+
headers: await headers.headers(),
|
|
1638
|
+
query: { disableCookieCache: true }
|
|
1576
1639
|
});
|
|
1577
1640
|
return session;
|
|
1578
1641
|
});
|
|
1579
1642
|
react.cache(async () => {
|
|
1580
|
-
var _a;
|
|
1643
|
+
var _a, _b, _c;
|
|
1581
1644
|
const session = await getCurrentSession();
|
|
1582
1645
|
if (!(session == null ? void 0 : session.user)) {
|
|
1583
1646
|
navigation.redirect("/login");
|
|
@@ -1589,13 +1652,13 @@ react.cache(async () => {
|
|
|
1589
1652
|
});
|
|
1590
1653
|
navigation.redirect("/login?error=account_banned");
|
|
1591
1654
|
}
|
|
1592
|
-
return session;
|
|
1655
|
+
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
1656
|
});
|
|
1594
|
-
function
|
|
1595
|
-
|
|
1596
|
-
{
|
|
1597
|
-
|
|
1598
|
-
|
|
1657
|
+
async function requireAdminApi() {
|
|
1658
|
+
const session = await auth.api.getSession({ headers: await headers.headers(), query: { disableCookieCache: true } });
|
|
1659
|
+
if (!(session == null ? void 0 : session.user)) return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1660
|
+
if (!hasRole(session.user.role)) return server.NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
1661
|
+
return session;
|
|
1599
1662
|
}
|
|
1600
1663
|
var MARKETING_SEGMENT_ID = config.RESEND_MARKETING_SEGMENT_ID;
|
|
1601
1664
|
async function setSubscribed(email, name, subscribed) {
|
|
@@ -1619,7 +1682,7 @@ async function setSubscribed(email, name, subscribed) {
|
|
|
1619
1682
|
}
|
|
1620
1683
|
}
|
|
1621
1684
|
|
|
1622
|
-
// lib/marketing-email.ts
|
|
1685
|
+
// lib/email/marketing-email.ts
|
|
1623
1686
|
var UNSUBSCRIBE_PLACEHOLDER = "{{{RESEND_UNSUBSCRIBE_URL}}}";
|
|
1624
1687
|
var escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1625
1688
|
function textToBroadcastHtml(text2) {
|
|
@@ -1669,19 +1732,10 @@ function unexpectedErrorMessage(error, message = "Something went wrong. Please t
|
|
|
1669
1732
|
return `${message} (ref: ${ref})`;
|
|
1670
1733
|
}
|
|
1671
1734
|
|
|
1672
|
-
// lib/marketing
|
|
1673
|
-
async function getSession() {
|
|
1674
|
-
return auth.api.getSession({ headers: await headers.headers() });
|
|
1675
|
-
}
|
|
1735
|
+
// lib/marketing/route.ts
|
|
1676
1736
|
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;
|
|
1737
|
+
const result = await requireAdminApi();
|
|
1738
|
+
return result instanceof server.NextResponse ? result : null;
|
|
1685
1739
|
}
|
|
1686
1740
|
var createSchema = zod.z.object({
|
|
1687
1741
|
segmentId: zod.z.string().min(1),
|
|
@@ -1780,7 +1834,7 @@ async function sendBroadcastPOST(_request, { params }) {
|
|
|
1780
1834
|
}
|
|
1781
1835
|
var subscriptionSchema = zod.z.object({ subscribed: zod.z.boolean() });
|
|
1782
1836
|
async function updateSubscriptionPUT(request) {
|
|
1783
|
-
const session = await getSession();
|
|
1837
|
+
const session = await auth.api.getSession({ headers: await headers.headers(), query: { disableCookieCache: true } });
|
|
1784
1838
|
if (!(session == null ? void 0 : session.user)) {
|
|
1785
1839
|
return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1786
1840
|
}
|