@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/auth/helpers.js
CHANGED
|
@@ -4,6 +4,9 @@ var components = require('@react-email/components');
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
5
|
require('server-only');
|
|
6
6
|
var react = require('react');
|
|
7
|
+
var child_process = require('child_process');
|
|
8
|
+
var fs = require('fs');
|
|
9
|
+
var path = require('path');
|
|
7
10
|
var betterAuth = require('better-auth');
|
|
8
11
|
var drizzle = require('better-auth/adapters/drizzle');
|
|
9
12
|
var cuid2 = require('@paralleldrive/cuid2');
|
|
@@ -22,6 +25,7 @@ var uaParserJs = require('ua-parser-js');
|
|
|
22
25
|
var geoip = require('geoip-lite');
|
|
23
26
|
var headers = require('next/headers');
|
|
24
27
|
var navigation = require('next/navigation');
|
|
28
|
+
var server = require('next/server');
|
|
25
29
|
|
|
26
30
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
27
31
|
|
|
@@ -47,17 +51,22 @@ var __spreadValues = (a, b) => {
|
|
|
47
51
|
return a;
|
|
48
52
|
};
|
|
49
53
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
50
|
-
var __esm = (fn, res) => function __init() {
|
|
51
|
-
|
|
54
|
+
var __esm = (fn, res, err) => function __init() {
|
|
55
|
+
if (err) throw err[0];
|
|
56
|
+
try {
|
|
57
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
58
|
+
} catch (e) {
|
|
59
|
+
throw err = [e], e;
|
|
60
|
+
}
|
|
52
61
|
};
|
|
53
62
|
var __export = (target, all) => {
|
|
54
63
|
for (var name in all)
|
|
55
64
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
56
65
|
};
|
|
57
66
|
|
|
58
|
-
// components/email/
|
|
59
|
-
var
|
|
60
|
-
__export(
|
|
67
|
+
// components/email/security/passkey-changed.tsx
|
|
68
|
+
var passkey_changed_exports = {};
|
|
69
|
+
__export(passkey_changed_exports, {
|
|
61
70
|
EmailTemplatePasskeyChange: () => EmailTemplatePasskeyChange
|
|
62
71
|
});
|
|
63
72
|
function EmailTemplatePasskeyChange({
|
|
@@ -118,14 +127,14 @@ function EmailTemplatePasskeyChange({
|
|
|
118
127
|
] }) }) }) })
|
|
119
128
|
] });
|
|
120
129
|
}
|
|
121
|
-
var
|
|
122
|
-
"components/email/
|
|
130
|
+
var init_passkey_changed = __esm({
|
|
131
|
+
"components/email/security/passkey-changed.tsx"() {
|
|
123
132
|
}
|
|
124
133
|
});
|
|
125
134
|
|
|
126
|
-
// components/email/
|
|
127
|
-
var
|
|
128
|
-
__export(
|
|
135
|
+
// components/email/auth/reset-password.tsx
|
|
136
|
+
var reset_password_exports = {};
|
|
137
|
+
__export(reset_password_exports, {
|
|
129
138
|
EmailTemplateResetPassword: () => EmailTemplateResetPassword
|
|
130
139
|
});
|
|
131
140
|
function EmailTemplateResetPassword({ firstName, url }) {
|
|
@@ -162,14 +171,14 @@ function EmailTemplateResetPassword({ firstName, url }) {
|
|
|
162
171
|
] }) }) })
|
|
163
172
|
] });
|
|
164
173
|
}
|
|
165
|
-
var
|
|
166
|
-
"components/email/
|
|
174
|
+
var init_reset_password = __esm({
|
|
175
|
+
"components/email/auth/reset-password.tsx"() {
|
|
167
176
|
}
|
|
168
177
|
});
|
|
169
178
|
|
|
170
|
-
// components/email/
|
|
171
|
-
var
|
|
172
|
-
__export(
|
|
179
|
+
// components/email/auth/verify-email.tsx
|
|
180
|
+
var verify_email_exports = {};
|
|
181
|
+
__export(verify_email_exports, {
|
|
173
182
|
EmailTemplateVerifyEmail: () => EmailTemplateVerifyEmail
|
|
174
183
|
});
|
|
175
184
|
function EmailTemplateVerifyEmail({ firstName, url }) {
|
|
@@ -198,8 +207,8 @@ function EmailTemplateVerifyEmail({ firstName, url }) {
|
|
|
198
207
|
] }) }) }) })
|
|
199
208
|
] });
|
|
200
209
|
}
|
|
201
|
-
var
|
|
202
|
-
"components/email/
|
|
210
|
+
var init_verify_email = __esm({
|
|
211
|
+
"components/email/auth/verify-email.tsx"() {
|
|
203
212
|
}
|
|
204
213
|
});
|
|
205
214
|
|
|
@@ -223,7 +232,7 @@ __export(schema_exports, {
|
|
|
223
232
|
verifications: () => verifications
|
|
224
233
|
});
|
|
225
234
|
|
|
226
|
-
// lib/maintenance.ts
|
|
235
|
+
// lib/config/maintenance.ts
|
|
227
236
|
var DEFAULT_MAINTENANCE_EXEMPT_PATHS = [
|
|
228
237
|
"/",
|
|
229
238
|
"/features",
|
|
@@ -290,7 +299,10 @@ var sessions = pgCore.pgTable("session", {
|
|
|
290
299
|
// Set by better-auth's admin plugin while this session is an admin
|
|
291
300
|
// impersonating another user; holds the impersonating admin's user id.
|
|
292
301
|
impersonatedBy: pgCore.text("impersonatedBy")
|
|
293
|
-
})
|
|
302
|
+
}, (table) => [
|
|
303
|
+
// Read by userId on every login (session count), ban/delete and the admin sessions view.
|
|
304
|
+
pgCore.index("session_user_idx").on(table.userId)
|
|
305
|
+
]);
|
|
294
306
|
var accounts = pgCore.pgTable("account", {
|
|
295
307
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
296
308
|
accountId: pgCore.text("accountId").notNull(),
|
|
@@ -339,7 +351,10 @@ var verifications = pgCore.pgTable("verification", {
|
|
|
339
351
|
});
|
|
340
352
|
var activityLogs = pgCore.pgTable("activity_log", {
|
|
341
353
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
342
|
-
|
|
354
|
+
// SET NULL, not cascade: deleting an admin must not erase the audit trail of
|
|
355
|
+
// what they did. actorEmail keeps who it was once the user row is gone.
|
|
356
|
+
userId: pgCore.text("userId").references(() => users.id, { onDelete: "set null" }),
|
|
357
|
+
actorEmail: pgCore.text("actorEmail"),
|
|
343
358
|
action: ActivityActionEnum("action").notNull(),
|
|
344
359
|
description: pgCore.text("description").notNull(),
|
|
345
360
|
ipAddress: pgCore.text("ipAddress"),
|
|
@@ -355,7 +370,11 @@ var activityLogs = pgCore.pgTable("activity_log", {
|
|
|
355
370
|
country: pgCore.text("country"),
|
|
356
371
|
city: pgCore.text("city"),
|
|
357
372
|
createdAt: pgCore.timestamp("createdAt").notNull().defaultNow()
|
|
358
|
-
})
|
|
373
|
+
}, (table) => [
|
|
374
|
+
// Per-user history, and the admin log's newest-first ordering.
|
|
375
|
+
pgCore.index("activity_log_user_created_idx").on(table.userId, table.createdAt),
|
|
376
|
+
pgCore.index("activity_log_created_idx").on(table.createdAt)
|
|
377
|
+
]);
|
|
359
378
|
var deviceFingerprints = pgCore.pgTable("device_fingerprint", {
|
|
360
379
|
id: pgCore.text("id").notNull().primaryKey().$defaultFn(() => cuid2.createId()),
|
|
361
380
|
userId: pgCore.text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
@@ -470,7 +489,9 @@ var envSchema = zod.z.object({
|
|
|
470
489
|
RESEND_MARKETING_SEGMENT_ID: zod.z.string().default(""),
|
|
471
490
|
// Sender for every transactional email. Must be on a domain verified in
|
|
472
491
|
// your Resend account.
|
|
473
|
-
|
|
492
|
+
// Resend's shared sandbox sender: works without a verified domain but only
|
|
493
|
+
// delivers to your own Resend account email. Set your verified domain for real use.
|
|
494
|
+
EMAIL_FROM: zod.z.string().default("Acme <onboarding@resend.dev>"),
|
|
474
495
|
// Display name for this deployment — shown as the authenticator-app label
|
|
475
496
|
// (2FA issuer) and the passkey relying-party name. Consuming projects set
|
|
476
497
|
// this in their own .env; defaults to the template name.
|
|
@@ -480,6 +501,9 @@ var envSchema = zod.z.object({
|
|
|
480
501
|
// a comma-separated list and sends through Resend (needs RESEND_API_KEY).
|
|
481
502
|
FEEDBACK_DISCORD_WEBHOOK_URL: zod.z.string().default(""),
|
|
482
503
|
FEEDBACK_EMAIL: zod.z.string().default(""),
|
|
504
|
+
// Seconds between feedback messages per user (default 30, 0 = off). Read
|
|
505
|
+
// straight from process.env in lib/feedback/route.ts; listed here for docs.
|
|
506
|
+
FEEDBACK_COOLDOWN_SECONDS: zod.z.string().default("30"),
|
|
483
507
|
// Web Push (example, see lib/push.ts). Generate keys with
|
|
484
508
|
// `bunx web-push generate-vapid-keys`. Blank = the notifications card is hidden.
|
|
485
509
|
// The public key is also read in the browser as NEXT_PUBLIC_VAPID_PUBLIC_KEY.
|
|
@@ -496,7 +520,12 @@ var envSchema = zod.z.object({
|
|
|
496
520
|
DB_DRIVER: zod.z.enum(["pg", "neon"]).default("pg"),
|
|
497
521
|
// Only relevant when DB_DRIVER=pg — whether the target Postgres server has SSL
|
|
498
522
|
// enabled. Self-hosted Postgres (e.g. via Docker/Dokploy) typically does not.
|
|
499
|
-
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true")
|
|
523
|
+
DATABASE_SSL: zod.z.string().default("false").transform((val) => val === "true"),
|
|
524
|
+
// With DATABASE_SSL=true the server certificate is verified. Set the CA (PEM,
|
|
525
|
+
// "\n" for newlines) for a self-signed or private CA; DATABASE_SSL_INSECURE=true
|
|
526
|
+
// skips verification (encrypts only). Both are read in config/pg-ssl.ts.
|
|
527
|
+
DATABASE_SSL_CA: zod.z.string().default(""),
|
|
528
|
+
DATABASE_SSL_INSECURE: zod.z.string().default("false")
|
|
500
529
|
});
|
|
501
530
|
|
|
502
531
|
// config/env.ts
|
|
@@ -510,24 +539,47 @@ if (!results.success) {
|
|
|
510
539
|
}
|
|
511
540
|
var config = results.data;
|
|
512
541
|
|
|
542
|
+
// config/pg-ssl.ts
|
|
543
|
+
function pgSslOptions() {
|
|
544
|
+
var _a;
|
|
545
|
+
if (process.env.DATABASE_SSL_INSECURE === "true") return { rejectUnauthorized: false };
|
|
546
|
+
const ca = (_a = process.env.DATABASE_SSL_CA) == null ? void 0 : _a.replace(/\\n/g, "\n");
|
|
547
|
+
return __spreadValues({ rejectUnauthorized: true }, ca ? { ca } : {});
|
|
548
|
+
}
|
|
549
|
+
|
|
513
550
|
// server/db/index.ts
|
|
514
551
|
var db;
|
|
515
552
|
if (config.DB_DRIVER === "pg") {
|
|
516
553
|
const pool = new pg.Pool({
|
|
517
554
|
connectionString: config.DATABASE_URL,
|
|
518
|
-
ssl: config.DATABASE_SSL ?
|
|
555
|
+
ssl: config.DATABASE_SSL ? pgSslOptions() : void 0,
|
|
556
|
+
// pg waits forever by default; a hung DB would otherwise freeze every request (proxy reads settings).
|
|
557
|
+
connectionTimeoutMillis: 5e3,
|
|
558
|
+
query_timeout: 15e3
|
|
559
|
+
// roomy enough for the 10k-row exports
|
|
519
560
|
});
|
|
520
561
|
db = nodePostgres.drizzle(pool, {
|
|
521
562
|
schema: schema_exports,
|
|
522
|
-
logger:
|
|
563
|
+
logger: process.env.NODE_ENV === "development"
|
|
523
564
|
});
|
|
524
565
|
console.log("\u{1F7E1} Using PostgreSQL (pg) driver");
|
|
525
|
-
} else if (config.DB_DRIVER === "neon") {
|
|
526
|
-
const sql4 = serverless.neon(config.DATABASE_URL);
|
|
527
|
-
db = neonHttp.drizzle(sql4, { schema: schema_exports, logger: true });
|
|
528
|
-
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
529
566
|
} else {
|
|
530
|
-
|
|
567
|
+
serverless.neonConfig.fetchFunction = (url, init) => fetch(url, __spreadProps(__spreadValues({}, init), { signal: AbortSignal.timeout(15e3) }));
|
|
568
|
+
const sql6 = serverless.neon(config.DATABASE_URL);
|
|
569
|
+
db = neonHttp.drizzle(sql6, { schema: schema_exports, logger: process.env.NODE_ENV === "development" });
|
|
570
|
+
console.log("\u{1F7E2} Using Neon (HTTP) driver");
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// node_modules/@better-auth/utils/dist/bytes.mjs
|
|
574
|
+
function toBufferSource(data) {
|
|
575
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
576
|
+
if (!ArrayBuffer.isView(data)) return data;
|
|
577
|
+
if (data.buffer instanceof ArrayBuffer) return data;
|
|
578
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
|
|
579
|
+
}
|
|
580
|
+
function toUint8Array(data) {
|
|
581
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
582
|
+
return new Uint8Array(data);
|
|
531
583
|
}
|
|
532
584
|
|
|
533
585
|
// node_modules/@better-auth/utils/dist/base32.mjs
|
|
@@ -536,9 +588,7 @@ function getAlphabet(hex2) {
|
|
|
536
588
|
}
|
|
537
589
|
function createDecodeMap(alphabet) {
|
|
538
590
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
539
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
540
|
-
decodeMap.set(alphabet[i], i);
|
|
541
|
-
}
|
|
591
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
542
592
|
return decodeMap;
|
|
543
593
|
}
|
|
544
594
|
function base32Encode(data, alphabet, padding) {
|
|
@@ -553,9 +603,7 @@ function base32Encode(data, alphabet, padding) {
|
|
|
553
603
|
result += alphabet[buffer >> shift & 31];
|
|
554
604
|
}
|
|
555
605
|
}
|
|
556
|
-
if (shift > 0)
|
|
557
|
-
result += alphabet[buffer << 5 - shift & 31];
|
|
558
|
-
}
|
|
606
|
+
if (shift > 0) result += alphabet[buffer << 5 - shift & 31];
|
|
559
607
|
if (padding) {
|
|
560
608
|
const padCount = (8 - result.length % 8) % 8;
|
|
561
609
|
result += "=".repeat(padCount);
|
|
@@ -568,12 +616,9 @@ function base32Decode(data, alphabet) {
|
|
|
568
616
|
let buffer = 0;
|
|
569
617
|
let bitsCollected = 0;
|
|
570
618
|
for (const char of data) {
|
|
571
|
-
if (char === "=")
|
|
572
|
-
break;
|
|
619
|
+
if (char === "=") break;
|
|
573
620
|
const value = decodeMap.get(char);
|
|
574
|
-
if (value === void 0) {
|
|
575
|
-
throw new Error(`Invalid Base32 character: ${char}`);
|
|
576
|
-
}
|
|
621
|
+
if (value === void 0) throw new Error(`Invalid Base32 character: ${char}`);
|
|
577
622
|
buffer = buffer << 5 | value;
|
|
578
623
|
bitsCollected += 5;
|
|
579
624
|
while (bitsCollected >= 8) {
|
|
@@ -585,68 +630,34 @@ function base32Decode(data, alphabet) {
|
|
|
585
630
|
}
|
|
586
631
|
var base32 = {
|
|
587
632
|
/**
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
633
|
+
* Encodes data into a Base32 string.
|
|
634
|
+
* @param data - The data to encode (ArrayBuffer, number-based TypedArray, or string).
|
|
635
|
+
* @param options - Encoding options.
|
|
636
|
+
* @returns The Base32 encoded string.
|
|
637
|
+
*/
|
|
593
638
|
encode(data, options = {}) {
|
|
594
639
|
var _a;
|
|
595
640
|
const alphabet = getAlphabet();
|
|
596
|
-
|
|
597
|
-
return base32Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
641
|
+
return base32Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
598
642
|
},
|
|
599
643
|
/**
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
644
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
645
|
+
* @param data - The Base32 encoded string or ArrayBuffer/TypedArray.
|
|
646
|
+
* @returns The decoded Uint8Array.
|
|
647
|
+
*/
|
|
604
648
|
decode(data) {
|
|
605
|
-
if (typeof data !== "string")
|
|
606
|
-
data = new TextDecoder().decode(data);
|
|
607
|
-
}
|
|
649
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
608
650
|
const alphabet = getAlphabet();
|
|
609
651
|
return base32Decode(data, alphabet);
|
|
610
652
|
}
|
|
611
653
|
};
|
|
612
654
|
|
|
613
|
-
// node_modules/@better-auth/utils/dist/
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
if (data.byteLength === 0) {
|
|
621
|
-
return "";
|
|
622
|
-
}
|
|
623
|
-
const buffer = new Uint8Array(data);
|
|
624
|
-
let result = "";
|
|
625
|
-
for (const byte of buffer) {
|
|
626
|
-
result += byte.toString(16).padStart(2, "0");
|
|
627
|
-
}
|
|
628
|
-
return result;
|
|
629
|
-
},
|
|
630
|
-
decode: (data) => {
|
|
631
|
-
if (!data) {
|
|
632
|
-
return "";
|
|
633
|
-
}
|
|
634
|
-
if (typeof data === "string") {
|
|
635
|
-
if (data.length % 2 !== 0) {
|
|
636
|
-
throw new Error("Invalid hexadecimal string");
|
|
637
|
-
}
|
|
638
|
-
if (!new RegExp(`^[${hexadecimal}]+$`).test(data)) {
|
|
639
|
-
throw new Error("Invalid hexadecimal string");
|
|
640
|
-
}
|
|
641
|
-
const result = new Uint8Array(data.length / 2);
|
|
642
|
-
for (let i = 0; i < data.length; i += 2) {
|
|
643
|
-
result[i / 2] = parseInt(data.slice(i, i + 2), 16);
|
|
644
|
-
}
|
|
645
|
-
return new TextDecoder().decode(result);
|
|
646
|
-
}
|
|
647
|
-
return new TextDecoder().decode(data);
|
|
648
|
-
}
|
|
649
|
-
};
|
|
655
|
+
// node_modules/@better-auth/utils/dist/index.mjs
|
|
656
|
+
function getWebcryptoSubtle() {
|
|
657
|
+
const cr = typeof globalThis !== "undefined" && globalThis.crypto;
|
|
658
|
+
if (cr && typeof cr.subtle === "object" && cr.subtle != null) return cr.subtle;
|
|
659
|
+
throw new Error("crypto.subtle must be defined");
|
|
660
|
+
}
|
|
650
661
|
|
|
651
662
|
// node_modules/@better-auth/utils/dist/base64.mjs
|
|
652
663
|
function getAlphabet2(urlSafe) {
|
|
@@ -664,9 +675,7 @@ function base64Encode(data, alphabet, padding) {
|
|
|
664
675
|
result += alphabet[buffer >> shift & 63];
|
|
665
676
|
}
|
|
666
677
|
}
|
|
667
|
-
if (shift > 0)
|
|
668
|
-
result += alphabet[buffer << 6 - shift & 63];
|
|
669
|
-
}
|
|
678
|
+
if (shift > 0) result += alphabet[buffer << 6 - shift & 63];
|
|
670
679
|
if (padding) {
|
|
671
680
|
const padCount = (4 - result.length % 4) % 4;
|
|
672
681
|
result += "=".repeat(padCount);
|
|
@@ -675,19 +684,14 @@ function base64Encode(data, alphabet, padding) {
|
|
|
675
684
|
}
|
|
676
685
|
function base64Decode(data, alphabet) {
|
|
677
686
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
678
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
679
|
-
decodeMap.set(alphabet[i], i);
|
|
680
|
-
}
|
|
687
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
681
688
|
const result = [];
|
|
682
689
|
let buffer = 0;
|
|
683
690
|
let bitsCollected = 0;
|
|
684
691
|
for (const char of data) {
|
|
685
|
-
if (char === "=")
|
|
686
|
-
break;
|
|
692
|
+
if (char === "=") break;
|
|
687
693
|
const value = decodeMap.get(char);
|
|
688
|
-
if (value === void 0) {
|
|
689
|
-
throw new Error(`Invalid Base64 character: ${char}`);
|
|
690
|
-
}
|
|
694
|
+
if (value === void 0) throw new Error(`Invalid Base64 character: ${char}`);
|
|
691
695
|
buffer = buffer << 6 | value;
|
|
692
696
|
bitsCollected += 6;
|
|
693
697
|
if (bitsCollected >= 8) {
|
|
@@ -701,15 +705,11 @@ var base64 = {
|
|
|
701
705
|
encode(data, options = {}) {
|
|
702
706
|
var _a;
|
|
703
707
|
const alphabet = getAlphabet2(false);
|
|
704
|
-
|
|
705
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
708
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
706
709
|
},
|
|
707
710
|
decode(data) {
|
|
708
|
-
if (typeof data !== "string")
|
|
709
|
-
|
|
710
|
-
}
|
|
711
|
-
const urlSafe = data.includes("-") || data.includes("_");
|
|
712
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
711
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
712
|
+
const alphabet = getAlphabet2(data.includes("-") || data.includes("_"));
|
|
713
713
|
return base64Decode(data, alphabet);
|
|
714
714
|
}
|
|
715
715
|
};
|
|
@@ -717,152 +717,142 @@ var base64Url = {
|
|
|
717
717
|
encode(data, options = {}) {
|
|
718
718
|
var _a;
|
|
719
719
|
const alphabet = getAlphabet2(true);
|
|
720
|
-
|
|
721
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
720
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
722
721
|
},
|
|
723
722
|
decode(data) {
|
|
724
|
-
|
|
725
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
726
|
-
return base64Decode(data, alphabet);
|
|
723
|
+
return base64Decode(data, getAlphabet2(data.includes("-") || data.includes("_")));
|
|
727
724
|
}
|
|
728
725
|
};
|
|
729
726
|
|
|
730
|
-
// node_modules/@
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
727
|
+
// node_modules/@noble/hashes/utils.js
|
|
728
|
+
var hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
729
|
+
// @ts-ignore
|
|
730
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
731
|
+
))();
|
|
732
|
+
function asciiToBase16(ch) {
|
|
733
|
+
return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
|
|
734
|
+
}
|
|
735
|
+
function hexToBytes(hex2) {
|
|
736
|
+
if (typeof hex2 !== "string")
|
|
737
|
+
throw new TypeError("hex string expected, got " + typeof hex2);
|
|
738
|
+
if (hasHexBuiltin) {
|
|
739
|
+
try {
|
|
740
|
+
return Uint8Array.fromHex(hex2);
|
|
741
|
+
} catch (error) {
|
|
742
|
+
if (error instanceof SyntaxError)
|
|
743
|
+
throw new RangeError(error.message);
|
|
744
|
+
throw error;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
const hl = hex2.length;
|
|
748
|
+
const al = hl / 2;
|
|
749
|
+
if (hl % 2)
|
|
750
|
+
throw new RangeError("hex string expected, got unpadded hex of length " + hl);
|
|
751
|
+
const array = new Uint8Array(al);
|
|
752
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
753
|
+
const n1 = asciiToBase16(hex2.charCodeAt(hi));
|
|
754
|
+
const n2 = asciiToBase16(hex2.charCodeAt(hi + 1));
|
|
755
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
756
|
+
const char = hex2[hi] + hex2[hi + 1];
|
|
757
|
+
throw new RangeError('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
758
|
+
}
|
|
759
|
+
array[ai] = n1 * 16 + n2;
|
|
760
|
+
}
|
|
761
|
+
return array;
|
|
736
762
|
}
|
|
737
763
|
|
|
764
|
+
// node_modules/@better-auth/utils/dist/hex.mjs
|
|
765
|
+
var toBytes = (data) => hexToBytes(data);
|
|
766
|
+
var hex = {
|
|
767
|
+
encode: (data) => {
|
|
768
|
+
const buffer = toUint8Array(data);
|
|
769
|
+
if (buffer.byteLength === 0) return "";
|
|
770
|
+
let result = "";
|
|
771
|
+
for (const byte of buffer) result += byte.toString(16).padStart(2, "0");
|
|
772
|
+
return result;
|
|
773
|
+
},
|
|
774
|
+
decode: (data) => {
|
|
775
|
+
if (!data) return "";
|
|
776
|
+
if (typeof data === "string") return new TextDecoder().decode(toBytes(data));
|
|
777
|
+
return new TextDecoder().decode(data);
|
|
778
|
+
},
|
|
779
|
+
toBytes
|
|
780
|
+
};
|
|
781
|
+
|
|
738
782
|
// node_modules/@better-auth/utils/dist/hmac.mjs
|
|
739
783
|
var createHMAC = (algorithm = "SHA-256", encoding = "none") => {
|
|
740
|
-
const
|
|
784
|
+
const hmac2 = {
|
|
741
785
|
importKey: async (key, keyUsage) => {
|
|
742
|
-
return getWebcryptoSubtle().importKey(
|
|
743
|
-
"
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
false,
|
|
747
|
-
[keyUsage]
|
|
748
|
-
);
|
|
786
|
+
return getWebcryptoSubtle().importKey("raw", toBufferSource(key), {
|
|
787
|
+
name: "HMAC",
|
|
788
|
+
hash: { name: algorithm }
|
|
789
|
+
}, false, [keyUsage]);
|
|
749
790
|
},
|
|
750
791
|
sign: async (hmacKey, data) => {
|
|
751
|
-
if (typeof hmacKey === "string")
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
hmacKey,
|
|
757
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
758
|
-
);
|
|
759
|
-
if (encoding === "hex") {
|
|
760
|
-
return hex.encode(signature);
|
|
761
|
-
}
|
|
762
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
763
|
-
return base64Url.encode(signature, {
|
|
764
|
-
padding: encoding !== "base64urlnopad"
|
|
765
|
-
});
|
|
766
|
-
}
|
|
792
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "sign");
|
|
793
|
+
const signature = await getWebcryptoSubtle().sign("HMAC", hmacKey, toBufferSource(data));
|
|
794
|
+
if (encoding === "hex") return hex.encode(signature);
|
|
795
|
+
if (encoding === "base64") return base64.encode(signature);
|
|
796
|
+
if (encoding === "base64url" || encoding === "base64urlnopad") return base64Url.encode(signature, { padding: encoding !== "base64urlnopad" });
|
|
767
797
|
return signature;
|
|
768
798
|
},
|
|
769
799
|
verify: async (hmacKey, data, signature) => {
|
|
770
|
-
if (typeof hmacKey === "string")
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
signature = hex.decode(signature);
|
|
775
|
-
}
|
|
776
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
777
|
-
signature = await base64.decode(signature);
|
|
778
|
-
}
|
|
779
|
-
return getWebcryptoSubtle().verify(
|
|
780
|
-
"HMAC",
|
|
781
|
-
hmacKey,
|
|
782
|
-
typeof signature === "string" ? new TextEncoder().encode(signature) : signature,
|
|
783
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
784
|
-
);
|
|
800
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "verify");
|
|
801
|
+
if (encoding === "hex") signature = typeof signature === "string" ? hex.toBytes(signature) : signature;
|
|
802
|
+
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") signature = await base64.decode(signature);
|
|
803
|
+
return getWebcryptoSubtle().verify("HMAC", hmacKey, toBufferSource(signature), toBufferSource(data));
|
|
785
804
|
}
|
|
786
805
|
};
|
|
787
|
-
return
|
|
806
|
+
return hmac2;
|
|
788
807
|
};
|
|
789
808
|
|
|
790
809
|
// node_modules/@better-auth/utils/dist/otp.mjs
|
|
791
810
|
var defaultPeriod = 30;
|
|
792
811
|
var defaultDigits = 6;
|
|
812
|
+
var hmac = createHMAC("SHA-1");
|
|
793
813
|
function constantTimeEqualOTP(input, expected) {
|
|
794
814
|
let difference = input.length ^ expected.length;
|
|
795
|
-
for (let i = 0; i < expected.length; i++)
|
|
796
|
-
difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
797
|
-
}
|
|
815
|
+
for (let i = 0; i < expected.length; i++) difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
798
816
|
return difference === 0;
|
|
799
817
|
}
|
|
800
|
-
async function generateHOTP(
|
|
801
|
-
counter,
|
|
802
|
-
digits,
|
|
803
|
-
hash = "SHA-1"
|
|
804
|
-
}) {
|
|
818
|
+
async function generateHOTP(key, { counter, digits }) {
|
|
805
819
|
const _digits = digits != null ? digits : defaultDigits;
|
|
806
|
-
if (_digits < 1 || _digits > 8)
|
|
807
|
-
|
|
808
|
-
}
|
|
809
|
-
const buffer = new ArrayBuffer(8);
|
|
820
|
+
if (_digits < 1 || _digits > 8) throw new TypeError("Digits must be between 1 and 8");
|
|
821
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
810
822
|
new DataView(buffer).setBigUint64(0, BigInt(counter), false);
|
|
811
823
|
const bytes = new Uint8Array(buffer);
|
|
812
|
-
const
|
|
824
|
+
const signature = await hmac.sign(key, bytes);
|
|
825
|
+
const hmacResult = new Uint8Array(signature);
|
|
813
826
|
const offset = hmacResult[hmacResult.length - 1] & 15;
|
|
814
|
-
|
|
815
|
-
const otp = truncated % 10 ** _digits;
|
|
816
|
-
return otp.toString().padStart(_digits, "0");
|
|
827
|
+
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");
|
|
817
828
|
}
|
|
818
|
-
async function generateTOTP(
|
|
829
|
+
async function generateTOTP(key, options) {
|
|
819
830
|
var _a, _b;
|
|
820
831
|
const digits = (_a = options == null ? void 0 : options.digits) != null ? _a : defaultDigits;
|
|
821
|
-
const
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
832
|
+
const milliseconds = ((_b = options == null ? void 0 : options.period) != null ? _b : defaultPeriod) * 1e3;
|
|
833
|
+
return await generateHOTP(key, {
|
|
834
|
+
counter: Math.floor(Date.now() / milliseconds),
|
|
835
|
+
digits
|
|
836
|
+
});
|
|
825
837
|
}
|
|
826
|
-
async function verifyTOTP(otp, {
|
|
827
|
-
window = 1,
|
|
828
|
-
digits = defaultDigits,
|
|
829
|
-
secret,
|
|
830
|
-
period = defaultPeriod
|
|
831
|
-
}) {
|
|
838
|
+
async function verifyTOTP(otp, { window = 1, digits = defaultDigits, key, period = defaultPeriod }) {
|
|
832
839
|
const milliseconds = period * 1e3;
|
|
833
840
|
const counter = Math.floor(Date.now() / milliseconds);
|
|
834
841
|
let matched = false;
|
|
835
|
-
for (let i = -window; i <= window; i++) {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
});
|
|
840
|
-
matched = constantTimeEqualOTP(otp, generatedOTP) || matched;
|
|
841
|
-
}
|
|
842
|
+
for (let i = -window; i <= window; i++) matched = constantTimeEqualOTP(otp, await generateHOTP(key, {
|
|
843
|
+
counter: counter + i,
|
|
844
|
+
digits
|
|
845
|
+
})) || matched;
|
|
842
846
|
return matched;
|
|
843
847
|
}
|
|
844
|
-
function generateQRCode({
|
|
845
|
-
issuer
|
|
846
|
-
account,
|
|
847
|
-
secret,
|
|
848
|
-
digits = defaultDigits,
|
|
849
|
-
period = defaultPeriod
|
|
850
|
-
}) {
|
|
851
|
-
const encodedIssuer = encodeURIComponent(issuer);
|
|
852
|
-
const encodedAccountName = encodeURIComponent(account);
|
|
853
|
-
const baseURI = `otpauth://totp/${encodedIssuer}:${encodedAccountName}`;
|
|
848
|
+
function generateQRCode({ issuer, account, secret, digits = defaultDigits, period = defaultPeriod }) {
|
|
849
|
+
const baseURI = `otpauth://totp/${encodeURIComponent(issuer)}:${encodeURIComponent(account)}`;
|
|
854
850
|
const params = new URLSearchParams({
|
|
855
|
-
secret: base32.encode(secret, {
|
|
856
|
-
padding: false
|
|
857
|
-
}),
|
|
851
|
+
secret: base32.encode(secret, { padding: false }),
|
|
858
852
|
issuer
|
|
859
853
|
});
|
|
860
|
-
if (digits !== void 0)
|
|
861
|
-
|
|
862
|
-
}
|
|
863
|
-
if (period !== void 0) {
|
|
864
|
-
params.set("period", period.toString());
|
|
865
|
-
}
|
|
854
|
+
if (digits !== void 0) params.set("digits", digits.toString());
|
|
855
|
+
if (period !== void 0) params.set("period", period.toString());
|
|
866
856
|
return `${baseURI}?${params.toString()}`;
|
|
867
857
|
}
|
|
868
858
|
var createOTP = (secret, opts) => {
|
|
@@ -870,14 +860,38 @@ var createOTP = (secret, opts) => {
|
|
|
870
860
|
const digits = (_a = void 0 ) != null ? _a : defaultDigits;
|
|
871
861
|
const period = (_b = void 0 ) != null ? _b : defaultPeriod;
|
|
872
862
|
return {
|
|
873
|
-
hotp: (counter) =>
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
863
|
+
hotp: async (counter) => {
|
|
864
|
+
return generateHOTP(await hmac.importKey(secret, "sign"), {
|
|
865
|
+
counter,
|
|
866
|
+
digits
|
|
867
|
+
});
|
|
868
|
+
},
|
|
869
|
+
totp: async () => {
|
|
870
|
+
return generateTOTP(await hmac.importKey(secret, "sign"), {
|
|
871
|
+
digits,
|
|
872
|
+
period
|
|
873
|
+
});
|
|
874
|
+
},
|
|
875
|
+
verify: async (otp, options) => {
|
|
876
|
+
return verifyTOTP(otp, __spreadValues({
|
|
877
|
+
key: await hmac.importKey(secret, "sign"),
|
|
878
|
+
digits,
|
|
879
|
+
period
|
|
880
|
+
}, options));
|
|
881
|
+
},
|
|
882
|
+
url: (issuer, account) => {
|
|
883
|
+
return generateQRCode({
|
|
884
|
+
issuer,
|
|
885
|
+
account,
|
|
886
|
+
secret,
|
|
887
|
+
digits,
|
|
888
|
+
period
|
|
889
|
+
});
|
|
890
|
+
}
|
|
877
891
|
};
|
|
878
892
|
};
|
|
879
893
|
|
|
880
|
-
// lib/two-factor.ts
|
|
894
|
+
// lib/auth/two-factor.ts
|
|
881
895
|
var CHALLENGED_PATHS = ["/callback/:id", "/one-tap/callback"];
|
|
882
896
|
var CODE_REQUIRED_PATHS = ["/two-factor/disable", "/two-factor/generate-backup-codes"];
|
|
883
897
|
function twoFactorPlugins(baseURL, { issuer, passwordless = false, challengeAfterOAuth = false }) {
|
|
@@ -950,6 +964,8 @@ async function logActivity({
|
|
|
950
964
|
try {
|
|
951
965
|
await db.insert(activityLogs).values({
|
|
952
966
|
userId,
|
|
967
|
+
// Snapshot the email at write time; survives deletion of the user row.
|
|
968
|
+
actorEmail: drizzleOrm.sql`(select "email" from "user" where "id" = ${userId})`,
|
|
953
969
|
action,
|
|
954
970
|
description,
|
|
955
971
|
ipAddress: ipAddress || null,
|
|
@@ -970,7 +986,7 @@ var countryNames = new Intl.DisplayNames(["en"], { type: "region" });
|
|
|
970
986
|
function getClientIp(headers2) {
|
|
971
987
|
var _a;
|
|
972
988
|
const forwardedFor = headers2 == null ? void 0 : headers2.get("x-forwarded-for");
|
|
973
|
-
if (forwardedFor) return forwardedFor.split(",")
|
|
989
|
+
if (forwardedFor) return forwardedFor.split(",").at(-1).trim();
|
|
974
990
|
return (_a = headers2 == null ? void 0 : headers2.get("x-real-ip")) != null ? _a : null;
|
|
975
991
|
}
|
|
976
992
|
function parseUserAgent(userAgent) {
|
|
@@ -1009,11 +1025,21 @@ function formatLocation({ country, city }) {
|
|
|
1009
1025
|
return [city, country].filter(Boolean).join(", ");
|
|
1010
1026
|
}
|
|
1011
1027
|
|
|
1012
|
-
// lib/cookie-names.ts
|
|
1028
|
+
// lib/security/cookie-names.ts
|
|
1013
1029
|
var LOGIN_REFERRER_COOKIE = "login_referrer";
|
|
1014
1030
|
var DEVICE_FINGERPRINT_HEADER = "x-device-fingerprint";
|
|
1015
1031
|
|
|
1016
|
-
// lib/auth-
|
|
1032
|
+
// lib/auth/base-url.ts
|
|
1033
|
+
function getBaseUrl() {
|
|
1034
|
+
const url = process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
|
|
1035
|
+
return url.replace(/\/+$/, "");
|
|
1036
|
+
}
|
|
1037
|
+
function otherActiveAdminExists(excludeIds) {
|
|
1038
|
+
const ids = drizzleOrm.sql.join(excludeIds.map((id) => drizzleOrm.sql`${id}`), drizzleOrm.sql`, `);
|
|
1039
|
+
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`;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// lib/auth/throttle-limits.ts
|
|
1017
1043
|
var WINDOW_MS = 15 * 60 * 1e3;
|
|
1018
1044
|
var MAX = 10;
|
|
1019
1045
|
var MAX_IP = MAX * 3;
|
|
@@ -1024,7 +1050,7 @@ function isOverLimit(row, now, max = MAX) {
|
|
|
1024
1050
|
return row.count >= max;
|
|
1025
1051
|
}
|
|
1026
1052
|
|
|
1027
|
-
// lib/auth
|
|
1053
|
+
// lib/auth/throttle.ts
|
|
1028
1054
|
async function isDeviceThrottled(fingerprint, max) {
|
|
1029
1055
|
try {
|
|
1030
1056
|
const [row] = await db.select({ count: authThrottle.count, windowStart: authThrottle.windowStart }).from(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint)).limit(1);
|
|
@@ -1048,8 +1074,10 @@ async function recordDeviceAttempt(fingerprint, meta) {
|
|
|
1048
1074
|
await db.insert(authThrottle).values(__spreadValues({ fingerprint, count: 1, windowStart: now }, seen)).onConflictDoUpdate({
|
|
1049
1075
|
target: authThrottle.fingerprint,
|
|
1050
1076
|
set: __spreadValues({
|
|
1051
|
-
|
|
1052
|
-
|
|
1077
|
+
// ISO strings, not Dates: pg sends a raw Date as server-local time, which a
|
|
1078
|
+
// tz-less `timestamp` column (stored as UTC) misreads on any non-UTC host.
|
|
1079
|
+
count: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then 1 else ${authThrottle.count} + 1 end`,
|
|
1080
|
+
windowStart: drizzleOrm.sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then ${now.toISOString()} else ${authThrottle.windowStart} end`
|
|
1053
1081
|
}, seen)
|
|
1054
1082
|
});
|
|
1055
1083
|
} catch (error) {
|
|
@@ -1068,15 +1096,9 @@ async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
|
1068
1096
|
console.error("auth-throttle prune failed", error);
|
|
1069
1097
|
}
|
|
1070
1098
|
}
|
|
1071
|
-
async function clearDeviceThrottle(fingerprint) {
|
|
1072
|
-
try {
|
|
1073
|
-
await db.delete(authThrottle).where(drizzleOrm.eq(authThrottle.fingerprint, fingerprint));
|
|
1074
|
-
} catch (error) {
|
|
1075
|
-
console.error("auth-throttle clear failed", error);
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
1099
|
var SETTINGS_ROW_ID = "default";
|
|
1079
1100
|
var CACHE_TTL_MS = 1e4;
|
|
1101
|
+
var FAILURE_CACHE_TTL_MS = 5e3;
|
|
1080
1102
|
var cached = null;
|
|
1081
1103
|
function fallbackSettings() {
|
|
1082
1104
|
return {
|
|
@@ -1119,7 +1141,9 @@ async function getSystemSettings() {
|
|
|
1119
1141
|
return value;
|
|
1120
1142
|
} catch (error) {
|
|
1121
1143
|
console.error("Failed to load system settings, failing open:", error);
|
|
1122
|
-
|
|
1144
|
+
const value = fallbackSettings();
|
|
1145
|
+
cached = { value, expiresAt: now + FAILURE_CACHE_TTL_MS };
|
|
1146
|
+
return value;
|
|
1123
1147
|
}
|
|
1124
1148
|
}
|
|
1125
1149
|
async function getEffectiveAuthFlags() {
|
|
@@ -1142,6 +1166,21 @@ async function getResend() {
|
|
|
1142
1166
|
config.RESEND_BROADCAST_API_KEY || config.RESEND_API_KEY;
|
|
1143
1167
|
|
|
1144
1168
|
// server/auth.ts
|
|
1169
|
+
function checkDepsOnce() {
|
|
1170
|
+
const flag = globalThis;
|
|
1171
|
+
if (process.env.NODE_ENV !== "development" || flag.__xkDepsChecked) return;
|
|
1172
|
+
flag.__xkDepsChecked = true;
|
|
1173
|
+
const script = path.join(
|
|
1174
|
+
/*turbopackIgnore: true*/
|
|
1175
|
+
process.cwd(),
|
|
1176
|
+
"node_modules/@xk2800/nextjs-template/scripts/check-deps.mjs"
|
|
1177
|
+
);
|
|
1178
|
+
if (!fs.existsSync(script)) return;
|
|
1179
|
+
child_process.execFile(process.execPath, [script], (_err, stdout) => {
|
|
1180
|
+
if (stdout == null ? void 0 : stdout.trim()) console.log(stdout);
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
checkDepsOnce();
|
|
1145
1184
|
async function logFailedLogin(ctx, log) {
|
|
1146
1185
|
var _a, _b, _c;
|
|
1147
1186
|
try {
|
|
@@ -1176,7 +1215,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1176
1215
|
userAgent: (_b = (_a = ctx.headers) == null ? void 0 : _a.get("user-agent")) != null ? _b : null
|
|
1177
1216
|
});
|
|
1178
1217
|
if (!config.RESEND_API_KEY) return;
|
|
1179
|
-
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (
|
|
1218
|
+
const { EmailTemplatePasskeyChange: EmailTemplatePasskeyChange2 } = await Promise.resolve().then(() => (init_passkey_changed(), passkey_changed_exports));
|
|
1180
1219
|
await (await getResend()).emails.send({
|
|
1181
1220
|
from: EMAIL_FROM,
|
|
1182
1221
|
to: [user.email],
|
|
@@ -1188,7 +1227,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
1188
1227
|
location: formatLocation(lookupGeoLocation(ip)),
|
|
1189
1228
|
ipAddress: ip || "Unknown",
|
|
1190
1229
|
when: (/* @__PURE__ */ new Date()).toUTCString(),
|
|
1191
|
-
manageUrl: `${
|
|
1230
|
+
manageUrl: `${getBaseUrl()}/dashboard/settings`
|
|
1192
1231
|
})
|
|
1193
1232
|
});
|
|
1194
1233
|
} catch (error) {
|
|
@@ -1239,6 +1278,15 @@ async function packageSessionCreated(log, ...[session, context]) {
|
|
|
1239
1278
|
console.error("Failed to log login activity", error);
|
|
1240
1279
|
}
|
|
1241
1280
|
}
|
|
1281
|
+
async function promoteFirstAdmin(user) {
|
|
1282
|
+
var _a;
|
|
1283
|
+
const adminEmail = (_a = process.env.ADMIN_EMAIL) == null ? void 0 : _a.trim().toLowerCase();
|
|
1284
|
+
if (!adminEmail || !user.emailVerified || user.email.toLowerCase() !== adminEmail) return;
|
|
1285
|
+
const [existing] = await db.select({ id: users.id }).from(users).where(drizzleOrm.eq(users.role, "admin")).limit(1);
|
|
1286
|
+
if (existing) return;
|
|
1287
|
+
await db.update(users).set({ role: "admin" }).where(drizzleOrm.eq(users.id, user.id));
|
|
1288
|
+
user.role = "admin";
|
|
1289
|
+
}
|
|
1242
1290
|
function createAuth(overrides = {}) {
|
|
1243
1291
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1244
1292
|
const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
|
|
@@ -1254,7 +1302,7 @@ function createAuth(overrides = {}) {
|
|
|
1254
1302
|
"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: {...} })."
|
|
1255
1303
|
);
|
|
1256
1304
|
}
|
|
1257
|
-
const baseURL =
|
|
1305
|
+
const baseURL = getBaseUrl();
|
|
1258
1306
|
const log = (_a = overrides.logActivity) != null ? _a : logActivity;
|
|
1259
1307
|
const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
|
|
1260
1308
|
issuer: config.APP_NAME,
|
|
@@ -1302,7 +1350,7 @@ function createAuth(overrides = {}) {
|
|
|
1302
1350
|
// callbackURL) — see app/(auth)/forgot-password and reset-password for
|
|
1303
1351
|
// the pages this points at.
|
|
1304
1352
|
async sendResetPassword({ user, url }) {
|
|
1305
|
-
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (
|
|
1353
|
+
const { EmailTemplateResetPassword: EmailTemplateResetPassword2 } = await Promise.resolve().then(() => (init_reset_password(), reset_password_exports));
|
|
1306
1354
|
await (await getResend()).emails.send({
|
|
1307
1355
|
from: EMAIL_FROM,
|
|
1308
1356
|
to: [user.email],
|
|
@@ -1318,8 +1366,11 @@ function createAuth(overrides = {}) {
|
|
|
1318
1366
|
// callback that flips users.emailVerified on click.
|
|
1319
1367
|
emailVerification: {
|
|
1320
1368
|
autoSignInAfterVerification: true,
|
|
1369
|
+
async afterEmailVerification(user) {
|
|
1370
|
+
await promoteFirstAdmin(user);
|
|
1371
|
+
},
|
|
1321
1372
|
async sendVerificationEmail({ user, url }) {
|
|
1322
|
-
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (
|
|
1373
|
+
const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (init_verify_email(), verify_email_exports));
|
|
1323
1374
|
await (await getResend()).emails.send({
|
|
1324
1375
|
from: EMAIL_FROM,
|
|
1325
1376
|
to: [user.email],
|
|
@@ -1361,6 +1412,7 @@ function createAuth(overrides = {}) {
|
|
|
1361
1412
|
create: {
|
|
1362
1413
|
async after(user, context) {
|
|
1363
1414
|
var _a2, _b2, _c2, _d2;
|
|
1415
|
+
await promoteFirstAdmin(user);
|
|
1364
1416
|
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));
|
|
1365
1417
|
}
|
|
1366
1418
|
}
|
|
@@ -1384,7 +1436,7 @@ function createAuth(overrides = {}) {
|
|
|
1384
1436
|
// available together.
|
|
1385
1437
|
hooks: {
|
|
1386
1438
|
before: api.createAuthMiddleware(async (ctx) => {
|
|
1387
|
-
var _a2, _b2, _c2, _d2;
|
|
1439
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
1388
1440
|
if (ctx.path === "/sign-in/email" || ctx.path === "/sign-up/email") {
|
|
1389
1441
|
const fingerprint = (_a2 = ctx.headers) == null ? void 0 : _a2.get(DEVICE_FINGERPRINT_HEADER);
|
|
1390
1442
|
const ip = getClientIp(ctx.headers);
|
|
@@ -1418,6 +1470,9 @@ function createAuth(overrides = {}) {
|
|
|
1418
1470
|
}
|
|
1419
1471
|
return;
|
|
1420
1472
|
}
|
|
1473
|
+
if (ctx.request && ((_c2 = ctx.path) == null ? void 0 : _c2.startsWith("/admin/")) && ctx.path !== "/admin/impersonate-user" && ctx.path !== "/admin/stop-impersonating") {
|
|
1474
|
+
throw new api.APIError("FORBIDDEN", { message: "Use the dashboard to manage users." });
|
|
1475
|
+
}
|
|
1421
1476
|
if (ctx.path === "/admin/impersonate-user" && overrides.impersonation === false) {
|
|
1422
1477
|
throw new api.APIError("FORBIDDEN", { message: "Impersonation is turned off." });
|
|
1423
1478
|
}
|
|
@@ -1428,8 +1483,8 @@ function createAuth(overrides = {}) {
|
|
|
1428
1483
|
throw new api.APIError("FORBIDDEN", { message: "Stop impersonating before deleting an account." });
|
|
1429
1484
|
}
|
|
1430
1485
|
if (current2.user.role === "admin") {
|
|
1431
|
-
const [
|
|
1432
|
-
if (
|
|
1486
|
+
const [other] = await db.select({ n: drizzleOrm.sql`1` }).from(users).where(otherActiveAdminExists([current2.user.id])).limit(1);
|
|
1487
|
+
if (!other) {
|
|
1433
1488
|
throw new api.APIError("FORBIDDEN", { message: "You're the only admin. Promote another user to admin first." });
|
|
1434
1489
|
}
|
|
1435
1490
|
}
|
|
@@ -1442,7 +1497,7 @@ function createAuth(overrides = {}) {
|
|
|
1442
1497
|
await log({
|
|
1443
1498
|
userId: current.session.impersonatedBy,
|
|
1444
1499
|
action: "impersonation_stopped",
|
|
1445
|
-
description: `Admin stopped impersonating ${(
|
|
1500
|
+
description: `Admin stopped impersonating ${(_e2 = (_d2 = target[0]) == null ? void 0 : _d2.email) != null ? _e2 : current.session.userId}`,
|
|
1446
1501
|
metadata: { impersonatedUserId: current.session.userId }
|
|
1447
1502
|
});
|
|
1448
1503
|
}
|
|
@@ -1478,8 +1533,6 @@ function createAuth(overrides = {}) {
|
|
|
1478
1533
|
if (failed) {
|
|
1479
1534
|
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
1480
1535
|
await logFailedLogin(ctx, log);
|
|
1481
|
-
} else {
|
|
1482
|
-
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
1483
1536
|
}
|
|
1484
1537
|
})
|
|
1485
1538
|
},
|
|
@@ -1560,14 +1613,40 @@ var auth = new Proxy({}, {
|
|
|
1560
1613
|
return Reflect.getOwnPropertyDescriptor(getDefaultAuth(), prop);
|
|
1561
1614
|
}
|
|
1562
1615
|
});
|
|
1616
|
+
|
|
1617
|
+
// lib/auth/pure.ts
|
|
1618
|
+
function hasRole(userRole, requiredRole) {
|
|
1619
|
+
if (!userRole) return false;
|
|
1620
|
+
if (requiredRole === "admin") {
|
|
1621
|
+
return userRole === "admin";
|
|
1622
|
+
}
|
|
1623
|
+
return userRole === "user" || userRole === "admin" || userRole === "tester";
|
|
1624
|
+
}
|
|
1625
|
+
function normalizeCallbackUrl(value) {
|
|
1626
|
+
if (typeof value !== "string" || !value.trim()) return "/dashboard";
|
|
1627
|
+
const candidate = value.trim();
|
|
1628
|
+
try {
|
|
1629
|
+
const appOrigin = new URL(getBaseUrl()).origin;
|
|
1630
|
+
const callbackUrl = new URL(candidate, appOrigin);
|
|
1631
|
+
if (callbackUrl.origin !== appOrigin) {
|
|
1632
|
+
return "/dashboard";
|
|
1633
|
+
}
|
|
1634
|
+
return `${callbackUrl.pathname}${callbackUrl.search}${callbackUrl.hash}` || "/dashboard";
|
|
1635
|
+
} catch (e) {
|
|
1636
|
+
return "/dashboard";
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
// lib/auth/helpers.ts
|
|
1563
1641
|
var getCurrentSession = react.cache(async () => {
|
|
1564
1642
|
const session = await auth.api.getSession({
|
|
1565
|
-
headers: await headers.headers()
|
|
1643
|
+
headers: await headers.headers(),
|
|
1644
|
+
query: { disableCookieCache: true }
|
|
1566
1645
|
});
|
|
1567
1646
|
return session;
|
|
1568
1647
|
});
|
|
1569
1648
|
var requireAuth = react.cache(async () => {
|
|
1570
|
-
var _a;
|
|
1649
|
+
var _a, _b, _c;
|
|
1571
1650
|
const session = await getCurrentSession();
|
|
1572
1651
|
if (!(session == null ? void 0 : session.user)) {
|
|
1573
1652
|
navigation.redirect("/login");
|
|
@@ -1579,15 +1658,8 @@ var requireAuth = react.cache(async () => {
|
|
|
1579
1658
|
});
|
|
1580
1659
|
navigation.redirect("/login?error=account_banned");
|
|
1581
1660
|
}
|
|
1582
|
-
return session;
|
|
1661
|
+
return __spreadProps(__spreadValues({}, session), { user: __spreadProps(__spreadValues({}, session.user), { role: (_c = (_b = user[0]) == null ? void 0 : _b.role) != null ? _c : session.user.role }) });
|
|
1583
1662
|
});
|
|
1584
|
-
function hasRole(userRole, requiredRole) {
|
|
1585
|
-
if (!userRole) return false;
|
|
1586
|
-
if (requiredRole === "admin") {
|
|
1587
|
-
return userRole === "admin";
|
|
1588
|
-
}
|
|
1589
|
-
return userRole === "user" || userRole === "admin" || userRole === "tester";
|
|
1590
|
-
}
|
|
1591
1663
|
async function requireRole(requiredRole) {
|
|
1592
1664
|
const session = await requireAuth();
|
|
1593
1665
|
if (!hasRole(session.user.role, requiredRole)) {
|
|
@@ -1595,24 +1667,17 @@ async function requireRole(requiredRole) {
|
|
|
1595
1667
|
}
|
|
1596
1668
|
return session;
|
|
1597
1669
|
}
|
|
1598
|
-
function
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
const callbackUrl = new URL(candidate, appOrigin);
|
|
1604
|
-
if (callbackUrl.origin !== appOrigin) {
|
|
1605
|
-
return "/dashboard";
|
|
1606
|
-
}
|
|
1607
|
-
return `${callbackUrl.pathname}${callbackUrl.search}${callbackUrl.hash}` || "/dashboard";
|
|
1608
|
-
} catch (e) {
|
|
1609
|
-
return "/dashboard";
|
|
1610
|
-
}
|
|
1670
|
+
async function requireAdminApi() {
|
|
1671
|
+
const session = await auth.api.getSession({ headers: await headers.headers(), query: { disableCookieCache: true } });
|
|
1672
|
+
if (!(session == null ? void 0 : session.user)) return server.NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
1673
|
+
if (!hasRole(session.user.role, "admin")) return server.NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
1674
|
+
return session;
|
|
1611
1675
|
}
|
|
1612
1676
|
|
|
1613
1677
|
exports.getCurrentSession = getCurrentSession;
|
|
1614
1678
|
exports.hasRole = hasRole;
|
|
1615
1679
|
exports.normalizeCallbackUrl = normalizeCallbackUrl;
|
|
1680
|
+
exports.requireAdminApi = requireAdminApi;
|
|
1616
1681
|
exports.requireAuth = requireAuth;
|
|
1617
1682
|
exports.requireRole = requireRole;
|
|
1618
1683
|
//# sourceMappingURL=helpers.js.map
|