@xk2800/nextjs-template 0.7.1-beta.2 → 0.7.1-beta.4
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 -1
- package/components/auth/deviceCheck.tsx +47 -6
- package/components/auth/oneTap.tsx +5 -5
- package/components/dashboard/admin/adminUserConsentCard.tsx +79 -0
- package/components/dashboard/admin/adminUserDevicesCard.tsx +80 -0
- package/components/dashboard/admin/systemSettingsForm.tsx +33 -0
- package/components/dashboard/admin/systemSettingsSection.tsx +8 -2
- package/components/site/cookie-banner.tsx +109 -7
- package/components/ui/file-upload.tsx +103 -2
- package/dist/activity/logger.js +30 -0
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +3 -3
- package/dist/activity/queries.d.mts +1 -1
- package/dist/activity/queries.d.ts +1 -1
- package/dist/activity/queries.js +30 -0
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +2 -2
- package/dist/admin/queries.d.mts +19 -1
- package/dist/admin/queries.d.ts +19 -1
- package/dist/admin/queries.js +58 -0
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +25 -4
- package/dist/admin/queries.mjs.map +1 -1
- package/dist/api/feedback.js +46 -2
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +7 -7
- package/dist/auth/helpers.d.mts +3 -3
- package/dist/auth/helpers.d.ts +3 -3
- package/dist/auth/helpers.js +44 -0
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +6 -6
- package/dist/auth/index.js +44 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +6 -6
- package/dist/auth-client/index.d.mts +16 -16
- package/dist/auth-client/index.d.ts +16 -16
- package/dist/{chunk-XWVAJXAG.mjs → chunk-4GGLYS5R.mjs} +20 -8
- package/dist/chunk-4GGLYS5R.mjs.map +1 -0
- package/dist/{chunk-KAEA35OC.mjs → chunk-6KTSULA5.mjs} +4 -4
- package/dist/{chunk-KAEA35OC.mjs.map → chunk-6KTSULA5.mjs.map} +1 -1
- package/dist/{chunk-N6ECRCHY.mjs → chunk-6OAHCEDJ.mjs} +4 -3
- package/dist/chunk-6OAHCEDJ.mjs.map +1 -0
- package/dist/{chunk-3MGEAGHU.mjs → chunk-F776DQAM.mjs} +10 -5
- package/dist/chunk-F776DQAM.mjs.map +1 -0
- package/dist/{chunk-WZDAMCUX.mjs → chunk-F7CG5CA3.mjs} +3 -3
- package/dist/{chunk-WZDAMCUX.mjs.map → chunk-F7CG5CA3.mjs.map} +1 -1
- package/dist/{chunk-VQ5B4MA7.mjs → chunk-FVLMSLTX.mjs} +4 -4
- package/dist/{chunk-VQ5B4MA7.mjs.map → chunk-FVLMSLTX.mjs.map} +1 -1
- package/dist/{chunk-ZQCALTKB.mjs → chunk-TR5XFBTD.mjs} +34 -4
- package/dist/chunk-TR5XFBTD.mjs.map +1 -0
- package/dist/db/index.d.mts +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +30 -0
- package/dist/db/index.js.map +1 -1
- package/dist/db/index.mjs +2 -2
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +30 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.js +30 -0
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +3 -3
- package/dist/{schema-UuqxoOzS.d.mts → schema-CN_Y6EXv.d.mts} +148 -2
- package/dist/{schema-UuqxoOzS.d.ts → schema-CN_Y6EXv.d.ts} +148 -2
- package/dist/sessions/queries.js +30 -0
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +2 -2
- package/dist/settings/queries.d.mts +4 -3
- package/dist/settings/queries.d.ts +4 -3
- package/dist/settings/queries.js +36 -0
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +3 -3
- package/dist/users/queries.js +30 -0
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +2 -2
- package/lib/cookie-consent.ts +72 -20
- package/lib/cookie-names.ts +47 -0
- package/lib/device-fingerprint.ts +66 -10
- package/package.json +7 -2
- package/dist/chunk-3MGEAGHU.mjs.map +0 -1
- package/dist/chunk-N6ECRCHY.mjs.map +0 -1
- package/dist/chunk-XWVAJXAG.mjs.map +0 -1
- package/dist/chunk-ZQCALTKB.mjs.map +0 -1
|
@@ -826,8 +826,8 @@ declare const authClient: better_auth_react.ReactAuthClient<{
|
|
|
826
826
|
$Infer: {
|
|
827
827
|
body: {
|
|
828
828
|
permissions: {
|
|
829
|
-
readonly user?: ("
|
|
830
|
-
readonly session?: ("
|
|
829
|
+
readonly user?: ("set-role" | "delete" | "update" | "list" | "create" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
830
|
+
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
831
831
|
};
|
|
832
832
|
} & {
|
|
833
833
|
userId?: string | undefined;
|
|
@@ -916,8 +916,8 @@ declare const authClient: better_auth_react.ReactAuthClient<{
|
|
|
916
916
|
admin: {
|
|
917
917
|
checkRolePermission: <R extends "user" | "admin">(data: {
|
|
918
918
|
permissions: {
|
|
919
|
-
readonly user?: ("
|
|
920
|
-
readonly session?: ("
|
|
919
|
+
readonly user?: ("set-role" | "delete" | "update" | "list" | "create" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
920
|
+
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
921
921
|
};
|
|
922
922
|
} & {
|
|
923
923
|
role: R;
|
|
@@ -2423,8 +2423,8 @@ declare const useSession: () => {
|
|
|
2423
2423
|
banned: boolean | null | undefined;
|
|
2424
2424
|
} & {
|
|
2425
2425
|
role?: string | null | undefined;
|
|
2426
|
-
banReason?: string | null | undefined;
|
|
2427
2426
|
banExpires?: Date | null | undefined;
|
|
2427
|
+
banReason?: string | null | undefined;
|
|
2428
2428
|
} & {
|
|
2429
2429
|
twoFactorEnabled: boolean | null | undefined;
|
|
2430
2430
|
} & {}>;
|
|
@@ -2450,7 +2450,7 @@ declare const useSession: () => {
|
|
|
2450
2450
|
};
|
|
2451
2451
|
declare const signIn: {
|
|
2452
2452
|
social: <FetchOptions extends better_auth.ClientFetchOption<Partial<{
|
|
2453
|
-
provider:
|
|
2453
|
+
provider: "github" | "apple" | "atlassian" | "cloudflare" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat" | (string & {});
|
|
2454
2454
|
callbackURL?: string | undefined;
|
|
2455
2455
|
newUserCallbackURL?: string | undefined;
|
|
2456
2456
|
errorCallbackURL?: string | undefined;
|
|
@@ -2475,7 +2475,7 @@ declare const signIn: {
|
|
|
2475
2475
|
additionalParams?: Record<string, string> | undefined;
|
|
2476
2476
|
additionalData?: Record<string, any> | undefined;
|
|
2477
2477
|
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, string | undefined> | undefined>>(data_0: better_auth.Prettify<Omit<{
|
|
2478
|
-
provider:
|
|
2478
|
+
provider: "github" | "apple" | "atlassian" | "cloudflare" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat" | (string & {});
|
|
2479
2479
|
callbackURL?: string | undefined;
|
|
2480
2480
|
newUserCallbackURL?: string | undefined;
|
|
2481
2481
|
errorCallbackURL?: string | undefined;
|
|
@@ -2502,7 +2502,7 @@ declare const signIn: {
|
|
|
2502
2502
|
} & {
|
|
2503
2503
|
fetchOptions?: FetchOptions | undefined;
|
|
2504
2504
|
}, "provider"> & {
|
|
2505
|
-
provider:
|
|
2505
|
+
provider: "github" | "apple" | "atlassian" | "cloudflare" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat" | (string & {});
|
|
2506
2506
|
fetchOptions?: FetchOptions | undefined;
|
|
2507
2507
|
}>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch.BetterFetchResponse<{
|
|
2508
2508
|
redirect: boolean;
|
|
@@ -2533,8 +2533,8 @@ declare const signIn: {
|
|
|
2533
2533
|
banned: boolean | null | undefined;
|
|
2534
2534
|
} & {
|
|
2535
2535
|
role?: string | null | undefined;
|
|
2536
|
-
banReason?: string | null | undefined;
|
|
2537
2536
|
banExpires?: Date | null | undefined;
|
|
2537
|
+
banReason?: string | null | undefined;
|
|
2538
2538
|
} & {
|
|
2539
2539
|
twoFactorEnabled: boolean | null | undefined;
|
|
2540
2540
|
} & {}>;
|
|
@@ -2581,8 +2581,8 @@ declare const signIn: {
|
|
|
2581
2581
|
banned: boolean | null | undefined;
|
|
2582
2582
|
} & {
|
|
2583
2583
|
role?: string | null | undefined;
|
|
2584
|
-
banReason?: string | null | undefined;
|
|
2585
2584
|
banExpires?: Date | null | undefined;
|
|
2585
|
+
banReason?: string | null | undefined;
|
|
2586
2586
|
} & {
|
|
2587
2587
|
twoFactorEnabled: boolean | null | undefined;
|
|
2588
2588
|
} & {}>;
|
|
@@ -3481,8 +3481,8 @@ declare const signUp: {
|
|
|
3481
3481
|
$Infer: {
|
|
3482
3482
|
body: {
|
|
3483
3483
|
permissions: {
|
|
3484
|
-
readonly user?: ("
|
|
3485
|
-
readonly session?: ("
|
|
3484
|
+
readonly user?: ("set-role" | "delete" | "update" | "list" | "create" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
3485
|
+
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
3486
3486
|
};
|
|
3487
3487
|
} & {
|
|
3488
3488
|
userId?: string | undefined;
|
|
@@ -3571,8 +3571,8 @@ declare const signUp: {
|
|
|
3571
3571
|
admin: {
|
|
3572
3572
|
checkRolePermission: <R extends "user" | "admin">(data: {
|
|
3573
3573
|
permissions: {
|
|
3574
|
-
readonly user?: ("
|
|
3575
|
-
readonly session?: ("
|
|
3574
|
+
readonly user?: ("set-role" | "delete" | "update" | "list" | "create" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
3575
|
+
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
3576
3576
|
};
|
|
3577
3577
|
} & {
|
|
3578
3578
|
role: R;
|
|
@@ -5155,8 +5155,8 @@ declare const signUp: {
|
|
|
5155
5155
|
banned: boolean | null | undefined;
|
|
5156
5156
|
} & {
|
|
5157
5157
|
role?: string | null | undefined;
|
|
5158
|
-
banReason?: string | null | undefined;
|
|
5159
5158
|
banExpires?: Date | null | undefined;
|
|
5159
|
+
banReason?: string | null | undefined;
|
|
5160
5160
|
} & {
|
|
5161
5161
|
twoFactorEnabled: boolean | null | undefined;
|
|
5162
5162
|
} & {}>;
|
|
@@ -5184,8 +5184,8 @@ declare const signUp: {
|
|
|
5184
5184
|
banned: boolean | null | undefined;
|
|
5185
5185
|
} & {
|
|
5186
5186
|
role?: string | null | undefined;
|
|
5187
|
-
banReason?: string | null | undefined;
|
|
5188
5187
|
banExpires?: Date | null | undefined;
|
|
5188
|
+
banReason?: string | null | undefined;
|
|
5189
5189
|
} & {
|
|
5190
5190
|
twoFactorEnabled: boolean | null | undefined;
|
|
5191
5191
|
} & {}>;
|
|
@@ -826,8 +826,8 @@ declare const authClient: better_auth_react.ReactAuthClient<{
|
|
|
826
826
|
$Infer: {
|
|
827
827
|
body: {
|
|
828
828
|
permissions: {
|
|
829
|
-
readonly user?: ("
|
|
830
|
-
readonly session?: ("
|
|
829
|
+
readonly user?: ("set-role" | "delete" | "update" | "list" | "create" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
830
|
+
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
831
831
|
};
|
|
832
832
|
} & {
|
|
833
833
|
userId?: string | undefined;
|
|
@@ -916,8 +916,8 @@ declare const authClient: better_auth_react.ReactAuthClient<{
|
|
|
916
916
|
admin: {
|
|
917
917
|
checkRolePermission: <R extends "user" | "admin">(data: {
|
|
918
918
|
permissions: {
|
|
919
|
-
readonly user?: ("
|
|
920
|
-
readonly session?: ("
|
|
919
|
+
readonly user?: ("set-role" | "delete" | "update" | "list" | "create" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
920
|
+
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
921
921
|
};
|
|
922
922
|
} & {
|
|
923
923
|
role: R;
|
|
@@ -2423,8 +2423,8 @@ declare const useSession: () => {
|
|
|
2423
2423
|
banned: boolean | null | undefined;
|
|
2424
2424
|
} & {
|
|
2425
2425
|
role?: string | null | undefined;
|
|
2426
|
-
banReason?: string | null | undefined;
|
|
2427
2426
|
banExpires?: Date | null | undefined;
|
|
2427
|
+
banReason?: string | null | undefined;
|
|
2428
2428
|
} & {
|
|
2429
2429
|
twoFactorEnabled: boolean | null | undefined;
|
|
2430
2430
|
} & {}>;
|
|
@@ -2450,7 +2450,7 @@ declare const useSession: () => {
|
|
|
2450
2450
|
};
|
|
2451
2451
|
declare const signIn: {
|
|
2452
2452
|
social: <FetchOptions extends better_auth.ClientFetchOption<Partial<{
|
|
2453
|
-
provider:
|
|
2453
|
+
provider: "github" | "apple" | "atlassian" | "cloudflare" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat" | (string & {});
|
|
2454
2454
|
callbackURL?: string | undefined;
|
|
2455
2455
|
newUserCallbackURL?: string | undefined;
|
|
2456
2456
|
errorCallbackURL?: string | undefined;
|
|
@@ -2475,7 +2475,7 @@ declare const signIn: {
|
|
|
2475
2475
|
additionalParams?: Record<string, string> | undefined;
|
|
2476
2476
|
additionalData?: Record<string, any> | undefined;
|
|
2477
2477
|
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, string | undefined> | undefined>>(data_0: better_auth.Prettify<Omit<{
|
|
2478
|
-
provider:
|
|
2478
|
+
provider: "github" | "apple" | "atlassian" | "cloudflare" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat" | (string & {});
|
|
2479
2479
|
callbackURL?: string | undefined;
|
|
2480
2480
|
newUserCallbackURL?: string | undefined;
|
|
2481
2481
|
errorCallbackURL?: string | undefined;
|
|
@@ -2502,7 +2502,7 @@ declare const signIn: {
|
|
|
2502
2502
|
} & {
|
|
2503
2503
|
fetchOptions?: FetchOptions | undefined;
|
|
2504
2504
|
}, "provider"> & {
|
|
2505
|
-
provider:
|
|
2505
|
+
provider: "github" | "apple" | "atlassian" | "cloudflare" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat" | (string & {});
|
|
2506
2506
|
fetchOptions?: FetchOptions | undefined;
|
|
2507
2507
|
}>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch.BetterFetchResponse<{
|
|
2508
2508
|
redirect: boolean;
|
|
@@ -2533,8 +2533,8 @@ declare const signIn: {
|
|
|
2533
2533
|
banned: boolean | null | undefined;
|
|
2534
2534
|
} & {
|
|
2535
2535
|
role?: string | null | undefined;
|
|
2536
|
-
banReason?: string | null | undefined;
|
|
2537
2536
|
banExpires?: Date | null | undefined;
|
|
2537
|
+
banReason?: string | null | undefined;
|
|
2538
2538
|
} & {
|
|
2539
2539
|
twoFactorEnabled: boolean | null | undefined;
|
|
2540
2540
|
} & {}>;
|
|
@@ -2581,8 +2581,8 @@ declare const signIn: {
|
|
|
2581
2581
|
banned: boolean | null | undefined;
|
|
2582
2582
|
} & {
|
|
2583
2583
|
role?: string | null | undefined;
|
|
2584
|
-
banReason?: string | null | undefined;
|
|
2585
2584
|
banExpires?: Date | null | undefined;
|
|
2585
|
+
banReason?: string | null | undefined;
|
|
2586
2586
|
} & {
|
|
2587
2587
|
twoFactorEnabled: boolean | null | undefined;
|
|
2588
2588
|
} & {}>;
|
|
@@ -3481,8 +3481,8 @@ declare const signUp: {
|
|
|
3481
3481
|
$Infer: {
|
|
3482
3482
|
body: {
|
|
3483
3483
|
permissions: {
|
|
3484
|
-
readonly user?: ("
|
|
3485
|
-
readonly session?: ("
|
|
3484
|
+
readonly user?: ("set-role" | "delete" | "update" | "list" | "create" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
3485
|
+
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
3486
3486
|
};
|
|
3487
3487
|
} & {
|
|
3488
3488
|
userId?: string | undefined;
|
|
@@ -3571,8 +3571,8 @@ declare const signUp: {
|
|
|
3571
3571
|
admin: {
|
|
3572
3572
|
checkRolePermission: <R extends "user" | "admin">(data: {
|
|
3573
3573
|
permissions: {
|
|
3574
|
-
readonly user?: ("
|
|
3575
|
-
readonly session?: ("
|
|
3574
|
+
readonly user?: ("set-role" | "delete" | "update" | "list" | "create" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
3575
|
+
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
3576
3576
|
};
|
|
3577
3577
|
} & {
|
|
3578
3578
|
role: R;
|
|
@@ -5155,8 +5155,8 @@ declare const signUp: {
|
|
|
5155
5155
|
banned: boolean | null | undefined;
|
|
5156
5156
|
} & {
|
|
5157
5157
|
role?: string | null | undefined;
|
|
5158
|
-
banReason?: string | null | undefined;
|
|
5159
5158
|
banExpires?: Date | null | undefined;
|
|
5159
|
+
banReason?: string | null | undefined;
|
|
5160
5160
|
} & {
|
|
5161
5161
|
twoFactorEnabled: boolean | null | undefined;
|
|
5162
5162
|
} & {}>;
|
|
@@ -5184,8 +5184,8 @@ declare const signUp: {
|
|
|
5184
5184
|
banned: boolean | null | undefined;
|
|
5185
5185
|
} & {
|
|
5186
5186
|
role?: string | null | undefined;
|
|
5187
|
-
banReason?: string | null | undefined;
|
|
5188
5187
|
banExpires?: Date | null | undefined;
|
|
5188
|
+
banReason?: string | null | undefined;
|
|
5189
5189
|
} & {
|
|
5190
5190
|
twoFactorEnabled: boolean | null | undefined;
|
|
5191
5191
|
} & {}>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { logActivity } from './chunk-
|
|
2
|
-
import { getClientIp, parseUserAgent, lookupGeoLocation, formatLocation, formatDeviceInfo, WINDOW_MS, isOverLimit, MAX_IP } from './chunk-
|
|
3
|
-
import { getEffectiveAuthFlags } from './chunk-
|
|
4
|
-
import { db } from './chunk-
|
|
5
|
-
import { users, sessions, passkeys, twoFactors, verifications, accounts, authThrottle } from './chunk-
|
|
1
|
+
import { logActivity } from './chunk-FVLMSLTX.mjs';
|
|
2
|
+
import { getClientIp, parseUserAgent, lookupGeoLocation, formatLocation, formatDeviceInfo, WINDOW_MS, isOverLimit, MAX_IP, RETENTION_MS } from './chunk-6OAHCEDJ.mjs';
|
|
3
|
+
import { getEffectiveAuthFlags } from './chunk-F776DQAM.mjs';
|
|
4
|
+
import { db } from './chunk-F7CG5CA3.mjs';
|
|
5
|
+
import { users, sessions, passkeys, twoFactors, verifications, accounts, authThrottle } from './chunk-TR5XFBTD.mjs';
|
|
6
6
|
import { config } from './chunk-TMJYAOC2.mjs';
|
|
7
7
|
import { __spreadValues, __spreadProps } from './chunk-3465SI5N.mjs';
|
|
8
8
|
import 'server-only';
|
|
9
9
|
import { betterAuth } from 'better-auth';
|
|
10
10
|
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
|
|
11
11
|
import { createId } from '@paralleldrive/cuid2';
|
|
12
|
-
import { sql, eq } from 'drizzle-orm';
|
|
12
|
+
import { sql, eq, lt } from 'drizzle-orm';
|
|
13
13
|
import { admin, twoFactor, oneTap } from 'better-auth/plugins';
|
|
14
14
|
import { passkey } from '@better-auth/passkey';
|
|
15
15
|
import { createAuthMiddleware, APIError, getSessionFromCtx } from 'better-auth/api';
|
|
@@ -47,6 +47,18 @@ async function recordDeviceAttempt(fingerprint, meta) {
|
|
|
47
47
|
} catch (error) {
|
|
48
48
|
console.error("auth-throttle write failed", error);
|
|
49
49
|
}
|
|
50
|
+
await pruneStaleRows(now);
|
|
51
|
+
}
|
|
52
|
+
var PRUNE_EVERY_MS = 60 * 60 * 1e3;
|
|
53
|
+
var lastPrune = 0;
|
|
54
|
+
async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
55
|
+
if (now.getTime() - lastPrune < PRUNE_EVERY_MS) return;
|
|
56
|
+
lastPrune = now.getTime();
|
|
57
|
+
try {
|
|
58
|
+
await db.delete(authThrottle).where(lt(authThrottle.lastAttemptAt, new Date(now.getTime() - RETENTION_MS)));
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error("auth-throttle prune failed", error);
|
|
61
|
+
}
|
|
50
62
|
}
|
|
51
63
|
async function clearDeviceThrottle(fingerprint) {
|
|
52
64
|
try {
|
|
@@ -454,5 +466,5 @@ var auth = new Proxy({}, {
|
|
|
454
466
|
});
|
|
455
467
|
|
|
456
468
|
export { EMAIL_FROM, auth, createAuth, getResend };
|
|
457
|
-
//# sourceMappingURL=chunk-
|
|
458
|
-
//# sourceMappingURL=chunk-
|
|
469
|
+
//# sourceMappingURL=chunk-4GGLYS5R.mjs.map
|
|
470
|
+
//# sourceMappingURL=chunk-4GGLYS5R.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/cookie-names.ts","../lib/auth-throttle.ts","../lib/resend.ts","../server/auth.ts"],"names":["eq","sql","current","adminPlugin"],"mappings":";;;;;;;;;;;;;;;;;AAMO,IAAM,qBAAA,GAAwB,gBAAA;AAM9B,IAAM,yBAAA,GAA4B,sBAAA;ACHzC,eAAsB,iBAAA,CAAkB,aAAqB,GAAA,EAAgC;AAC3F,EAAA,IAAI;AACF,IAAA,MAAM,CAAC,GAAG,CAAA,GAAI,MAAM,EAAA,CACjB,MAAA,CAAO,EAAE,KAAA,EAAO,YAAA,CAAa,KAAA,EAAO,WAAA,EAAa,YAAA,CAAa,WAAA,EAAa,CAAA,CAC3E,IAAA,CAAK,YAAY,CAAA,CACjB,KAAA,CAAM,EAAA,CAAG,YAAA,CAAa,WAAA,EAAa,WAAW,CAAC,CAAA,CAC/C,KAAA,CAAM,CAAC,CAAA;AACV,IAAA,OAAO,WAAA,CAAY,GAAA,EAAK,IAAA,CAAK,GAAA,IAAO,GAAG,CAAA;AAAA,EACzC,SAAS,KAAA,EAAO;AAEd,IAAA,OAAA,CAAQ,KAAA,CAAM,+CAA+C,KAAK,CAAA;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACF;AAcA,eAAs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CAAC,MAAA,EAAQ,CAAA,GAAI;AAAC;AACpF,GACD,CAAA;AACH;AAUA,IAAI,KAAA;AACJ,SAAS,cAAA,GAAiB;AACxB,EAAA,IAAI,CAAC,KAAA,EAAO,KAAA,GAAQ,UAAA,EAAW;AAC/B,EAAA,OAAO,KAAA;AACT;AAEO,IAAM,IAAA,GAAO,IAAI,KAAA,CAAM,EAAC,EAAoC;AAAA,EACjE,GAAA,CAAI,SAAS,IAAA,EAAM;AACjB,IAAA,MAAM,WAAW,cAAA,EAAe;AAChC,IAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,GAAA,CAAI,QAAA,EAAU,IAAI,CAAA;AACxC,IAAA,OAAO,OAAO,KAAA,KAAU,UAAA,GAAa,KAAA,CAAM,IAAA,CAAK,QAAQ,CAAA,GAAI,KAAA;AAAA,EAC9D,CAAA;AAAA;AAAA;AAAA;AAAA,EAIA,GAAA,CAAI,SAAS,IAAA,EAAM;AACjB,IAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,cAAA,EAAe,EAAG,IAAI,CAAA;AAAA,EAC3C,CAAA;AAAA,EACA,QAAQ,OAAA,EAAS;AACf,IAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,cAAA,EAAgB,CAAA;AAAA,EACzC,CAAA;AAAA,EACA,wBAAA,CAAyB,SAAS,IAAA,EAAM;AACtC,IAAA,OAAO,OAAA,CAAQ,wBAAA,CAAyB,cAAA,EAAe,EAAG,IAAI,CAAA;AAAA,EAChE;AACF,CAAC","file":"chunk-4GGLYS5R.mjs","sourcesContent":["// Shared cookie/header names used by both client components and server/auth.ts\n// — no \"server-only\" guard, since both sides need them.\n\n// Stashes the page a social sign-in was initiated from, so the login-activity\n// log shows the real referrer instead of the OAuth provider's own domain\n// (e.g. accounts.google.com) once the browser redirects back.\nexport const LOGIN_REFERRER_COOKIE = 'login_referrer'\n\n// Carries the client's FingerprintJS visitorId on /sign-in/email and\n// /sign-up/email requests — the key for the per-device abuse throttle\n// (see lib/auth-throttle.ts). A header, not a cookie, so it's only sent on\n// the auth calls that need it, not every request.\nexport const DEVICE_FINGERPRINT_HEADER = 'x-device-fingerprint'\n\n// The visitor's cookie choice (lib/cookie-consent.ts): \"all\", \"necessary\", or\n// a comma list of the purposes they ticked under \"Customize\", e.g.\n// \"fingerprint\" — one choice per purpose, as regulators like the CNIL expect.\nexport const COOKIE_CONSENT_COOKIE = 'cookie_consent'\n\n// \"fingerprint\": FingerprintJS device id (new-device alerts, sign-in throttle,\n// shared-device detection, admin Devices card). \"onetap\": Google One Tap,\n// whose script may set Google's own cookies.\nexport type ConsentPurpose = 'fingerprint' | 'onetap'\nexport const CONSENT_PURPOSES: ConsentPurpose[] = ['fingerprint', 'onetap']\n\n// Version of the consent wording (banner text + privacy page purposes),\n// stored with each consent record (consent_log.version) so you can show which\n// text a user agreed to. Bump it when that wording changes materially.\nexport const CONSENT_VERSION = 1\n\n// A well-formed cookie_consent value: \"all\", \"necessary\", or a comma list of\n// known purposes. Used to validate what the client sends to app/api/consent.\nexport function isValidConsent(value: unknown): value is string {\n if (value === 'all' || value === 'necessary') return true\n if (typeof value !== 'string' || !value) return false\n const parts = value.split(',')\n return new Set(parts).size === parts.length && parts.every((p) => (CONSENT_PURPOSES as string[]).includes(p))\n}\n\n// Does a cookie_consent value allow this purpose? Plain function, no React,\n// so route handlers can use it too (app/api/device-check).\nexport function consentAllows(value: string | null | undefined, purpose: ConsentPurpose): boolean {\n if (value === 'all') return true\n if (!value || value === 'necessary') return false\n return value.split(',').includes(purpose)\n}\n\n// Consent mode, set by proxy.ts from the admin's System Settings toggle\n// (\"1\" = consent required, \"0\" = not). Read by lib/cookie-consent.ts.\nexport const CONSENT_REQUIRED_COOKIE = 'consent_required'\n\n// FingerprintJS signals that are never sent or stored. Accessibility\n// preferences can hint at a disability (GDPR Art. 9 health data); colorGamut\n// mostly tracks display hardware but is read alongside them. Filtered on the\n// client (lib/device-fingerprint.ts) and again on the server\n// (app/api/device-check), since the client can't be trusted.\nexport const EXCLUDED_SIGNALS = new Set([\n 'reducedMotion', 'reducedTransparency', 'contrast', 'forcedColors',\n 'invertedColors', 'monochrome', 'colorGamut',\n])\n","import \"server-only\"\nimport { eq, lt, sql } from \"drizzle-orm\"\nimport { db } from \"../server/db\"\nimport { authThrottle } from \"../server/db/schema\"\nimport { RETENTION_MS, WINDOW_MS, isOverLimit } from \"./auth-throttle-limits\"\n\n// Is this key (device fingerprint, or \"ip:<address>\" backstop) currently over\n// the cap? Read-only — the caller (server/auth.ts before-hook) decides\n// whether to 429.\nexport async function isDeviceThrottled(fingerprint: string, max?: number): Promise<boolean> {\n try {\n const [row] = await db\n .select({ count: authThrottle.count, windowStart: authThrottle.windowStart })\n .from(authThrottle)\n .where(eq(authThrottle.fingerprint, fingerprint))\n .limit(1)\n return isOverLimit(row, Date.now(), max)\n } catch (error) {\n // Fail open — a throttle-store hiccup must never lock everyone out of sign-in.\n console.error(\"auth-throttle read failed, allowing request\", error)\n return false\n }\n}\n\nexport type AttemptMeta = {\n ipAddress: string | null\n userAgent: string | null\n email: string | null\n kind: \"signin\" | \"signup\"\n}\n\n// Atomic upsert: new row at 1, +1 within the live window, or reset to 1 when\n// the previous window has elapsed. One statement, so a device hammering the\n// endpoint (the whole point) can't race its own counter. The meta fields are\n// overwritten every time — they're \"last seen from this device\", for the\n// admin panel's block-list view (lib/admin-queries.ts).\nexport async function recordDeviceAttempt(fingerprint: string, meta: AttemptMeta): Promise<void> {\n const now = new Date()\n const cutoff = new Date(now.getTime() - WINDOW_MS)\n const seen = {\n lastAttemptAt: now,\n ipAddress: meta.ipAddress,\n userAgent: meta.userAgent,\n lastEmail: meta.email,\n lastKind: meta.kind,\n }\n try {\n await db\n .insert(authThrottle)\n .values({ fingerprint, count: 1, windowStart: now, ...seen })\n .onConflictDoUpdate({\n target: authThrottle.fingerprint,\n set: {\n count: sql`case when ${authThrottle.windowStart} < ${cutoff} then 1 else ${authThrottle.count} + 1 end`,\n windowStart: sql`case when ${authThrottle.windowStart} < ${cutoff} then ${now} else ${authThrottle.windowStart} end`,\n ...seen,\n },\n })\n } catch (error) {\n console.error(\"auth-throttle write failed\", error)\n }\n await pruneStaleRows(now)\n}\n\n// Retention sweep piggybacked on the write path, so no cron is needed.\n// ponytail: runs at most hourly per server instance, and only when someone\n// attempts a sign-in — a site with zero attempts keeps stale rows until the\n// next one. Call pruneStaleRows() from a cron if you need a hard guarantee.\nconst PRUNE_EVERY_MS = 60 * 60 * 1000\nlet lastPrune = 0\n\nexport async function pruneStaleRows(now = new Date()): Promise<void> {\n if (now.getTime() - lastPrune < PRUNE_EVERY_MS) return\n lastPrune = now.getTime()\n try {\n await db\n .delete(authThrottle)\n .where(lt(authThrottle.lastAttemptAt, new Date(now.getTime() - RETENTION_MS)))\n } catch (error) {\n console.error(\"auth-throttle prune failed\", error)\n }\n}\n\nexport async function clearDeviceThrottle(fingerprint: string): Promise<void> {\n try {\n await db.delete(authThrottle).where(eq(authThrottle.fingerprint, fingerprint))\n } catch (error) {\n console.error(\"auth-throttle clear failed\", error)\n }\n}\n","import \"server-only\"\nimport type { Resend } from \"resend\"\nimport { config } from \"@/config/env\"\n\n// From env, not hardcoded: scaffolded apps run this module from the package's\n// bundled auth, so a local edit here would never reach their auth emails.\nexport const EMAIL_FROM = config.EMAIL_FROM\n\n// Loaded on first send, so projects that never send email don't pay for it\n// at startup.\nlet resend: Resend | undefined\nexport async function getResend() {\n if (!resend) {\n const { Resend } = await import(\"resend\")\n resend = new Resend(config.RESEND_API_KEY)\n }\n return resend\n}\n","import \"server-only\"\nimport { betterAuth, type BetterAuthOptions } from \"better-auth\"\nimport { drizzleAdapter } from \"better-auth/adapters/drizzle\"\nimport { createId } from \"@paralleldrive/cuid2\"\nimport { eq, sql } from \"drizzle-orm\"\nimport { db } from \"./db\"\nimport { users, accounts, sessions, verifications, twoFactors, passkeys } from \"./db/schema\"\nimport { config } from \"@/config/env\"\nimport { oneTap, admin as adminPlugin, twoFactor } from \"better-auth/plugins\";\nimport { passkey } from \"@better-auth/passkey\";\nimport { createAuthMiddleware, getSessionFromCtx, APIError } from \"better-auth/api\"\nimport { logActivity } from \"@/lib/activity-logger\"\nimport { getClientIp, parseUserAgent, lookupGeoLocation, formatDeviceInfo, formatLocation } from \"@/lib/request-info\"\nimport { LOGIN_REFERRER_COOKIE, DEVICE_FINGERPRINT_HEADER } from \"@/lib/cookie-names\"\nimport { isDeviceThrottled, recordDeviceAttempt, clearDeviceThrottle } from \"@/lib/auth-throttle\"\nimport { MAX_IP } from \"@/lib/auth-throttle-limits\"\nimport { getEffectiveAuthFlags } from \"@/lib/settings-queries\"\nimport { getResend, EMAIL_FROM } from \"@/lib/resend\"\n// Email templates are imported lazily where they're sent, so\n// @react-email/components only loads when an email goes out.\n\ntype AuthOverrides = {\n // Merged with (not replacing) the default `google` provider below, so\n // consuming projects can add e.g. `apple` without forking this file.\n socialProviders?: BetterAuthOptions[\"socialProviders\"]\n}\n\n// A failed credential sign-in, written to the activity feed — but only when\n// the attempted email maps to a real account (activityLogs.userId is NOT\n// NULL, and a miss has no user to attribute the row to). Best-effort: runs\n// in an after-hook and must never disturb the sign-in response.\nasync function logFailedLogin(ctx: { body?: unknown; headers?: Headers | null }) {\n try {\n const raw = (ctx.body as { email?: unknown } | undefined)?.email\n const email = typeof raw === \"string\" ? raw.toLowerCase() : null\n if (!email) return\n\n const [user] = await db\n .select({ id: users.id })\n .from(users)\n .where(eq(users.email, email))\n .limit(1)\n if (!user) return\n\n await logActivity({\n userId: user.id,\n action: \"login_failed\",\n description: \"Failed login attempt\",\n ipAddress: getClientIp(ctx.headers),\n userAgent: ctx.headers?.get(\"user-agent\") ?? null,\n })\n } catch (error) {\n console.error(\"Failed to log login_failed activity\", error)\n }\n}\n\n// Email the account owner that a passkey was added or removed. Runs from the\n// auth `after` hook on a successful /passkey/verify-registration or\n// /passkey/delete-passkey; best-effort — a mail failure must not fail the\n// endpoint. Also written to the activity feed. Self-disables when Resend\n// isn't configured.\nasync function notifyPasskeyChange(\n ctx: Parameters<Parameters<typeof createAuthMiddleware>[0]>[0],\n action: \"added\" | \"removed\",\n) {\n try {\n const session = await getSessionFromCtx(ctx)\n const user = session?.user\n if (!user) return\n\n const ip = getClientIp(ctx.headers)\n\n await logActivity({\n userId: user.id,\n action: action === \"added\" ? \"passkey_added\" : \"passkey_removed\",\n description: `Passkey ${action}`,\n ipAddress: ip,\n userAgent: ctx.headers?.get(\"user-agent\") ?? null,\n })\n\n if (!config.RESEND_API_KEY) return\n\n const { EmailTemplatePasskeyChange } = await import(\"@/components/email/email-template-passkey-change\")\n await (await getResend()).emails.send({\n from: EMAIL_FROM,\n to: [user.email],\n subject: action === \"added\" ? \"A passkey was added to your account\" : \"A passkey was removed from your account\",\n react: EmailTemplatePasskeyChange({\n firstName: user.name || \"there\",\n action,\n device: formatDeviceInfo(parseUserAgent(ctx.headers?.get(\"user-agent\") ?? null)),\n location: formatLocation(lookupGeoLocation(ip)),\n ipAddress: ip || \"Unknown\",\n when: new Date().toUTCString(),\n manageUrl: `${process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || \"\"}/dashboard/settings`,\n }),\n })\n } catch (error) {\n console.error(\"Failed to send passkey-change notification\", error)\n }\n}\n\nexport function createAuth(overrides: AuthOverrides = {}) {\n const socialProviders: NonNullable<BetterAuthOptions[\"socialProviders\"]> = {\n ...(config.AUTH_ENABLE_GOOGLE ? {\n google: {\n clientId: process.env.AUTH_GOOGLE_ID || process.env.GOOGLE_CLIENT_ID || \"\",\n clientSecret: process.env.AUTH_GOOGLE_SECRET || process.env.GOOGLE_CLIENT_SECRET || \"\",\n },\n } : {}),\n ...overrides.socialProviders,\n }\n const emailAndPasswordEnabled = config.AUTH_ENABLE_EMAIL_PASSWORD\n\n // Guard on the *final* merged config, after overrides.socialProviders is applied —\n // this only fails when there's truly no way to sign in. A project that disables both\n // built-ins via AUTH_ENABLE_GOOGLE=false / AUTH_ENABLE_EMAIL_PASSWORD=false but adds\n // its own provider (e.g. apple) here is a valid config and won't trip this.\n const hasEnabledSocialProvider = Object.values(socialProviders).some(Boolean)\n\n if (!hasEnabledSocialProvider && !emailAndPasswordEnabled) {\n throw new Error(\n \"No auth provider is enabled — every social provider is off and emailAndPassword.enabled is false. \" +\n \"Enable AUTH_ENABLE_GOOGLE / AUTH_ENABLE_EMAIL_PASSWORD, or pass your own provider via createAuth({ socialProviders: {...} }).\"\n )\n }\n\n // Shared by the `baseURL` field below and the passkey plugin's rpID/origin\n // — WebAuthn credentials are bound to this exact origin, so it must never\n // fall back to better-auth's own \"localhost\" passkey default in production.\n const baseURL = process.env.NEXTAUTH_URL || process.env.BETTER_AUTH_URL || \"http://localhost:3000\"\n\n return betterAuth({\n database: drizzleAdapter(db, {\n provider: \"pg\",\n schema: {\n user: users,\n account: accounts,\n session: sessions,\n verification: verifications,\n twoFactor: twoFactors,\n passkey: passkeys,\n },\n }),\n\n // Session configuration (30 days expiration matching previous NextAuth setup)\n session: {\n expiresIn: 60 * 60 * 24 * 30, // 30 days\n updateAge: 60 * 60 * 24, // Update session every 24 hours\n cookieCache: {\n enabled: true, // Enable hybrid session caching for performance\n maxAge: 5 * 60, // 5 minutes\n }\n },\n\n // Email & Password Authentication (replaces Credentials provider)\n // Toggle per-project via AUTH_ENABLE_EMAIL_PASSWORD in that project's own .env.*\n emailAndPassword: {\n enabled: emailAndPasswordEnabled,\n requireEmailVerification: false,\n // `url` is fully composed by better-auth (baseURL + verification token +\n // callbackURL) — see app/(auth)/forgot-password and reset-password for\n // the pages this points at.\n async sendResetPassword({ user, url }) {\n const { EmailTemplateResetPassword } = await import(\"@/components/email/email-template-reset-password\")\n await (await getResend()).emails.send({\n from: EMAIL_FROM,\n to: [user.email],\n subject: \"Reset your password\",\n react: EmailTemplateResetPassword({ firstName: user.name || \"there\", url }),\n })\n },\n },\n\n // Email verification. `requireEmailVerification` above stays false, so this\n // is opt-in: users trigger it from the dashboard via\n // authClient.sendVerificationEmail(). better-auth composes `url`\n // (baseURL + token + callbackURL) and serves the /api/auth/verify-email\n // callback that flips users.emailVerified on click.\n emailVerification: {\n autoSignInAfterVerification: true,\n async sendVerificationEmail({ user, url }) {\n const { EmailTemplateVerifyEmail } = await import(\"@/components/email/email-template-verify-email\")\n await (await getResend()).emails.send({\n from: EMAIL_FROM,\n to: [user.email],\n subject: \"Confirm your email\",\n react: EmailTemplateVerifyEmail({ firstName: user.name || \"there\", url }),\n })\n },\n },\n\n // Social Providers — google is included by default; toggle per-project via\n // AUTH_ENABLE_GOOGLE. overrides.socialProviders can still add more (or replace it).\n socialProviders,\n\n // User schema configuration\n user: {\n additionalFields: {\n role: {\n type: \"string\",\n required: false,\n defaultValue: \"user\",\n input: false, // Prevent users from setting their own role\n },\n },\n // Self-service \"Delete account\" (dashboard Settings → Danger zone).\n // Credential users confirm with their password; OAuth-only users have\n // no password, so better-auth instead requires a session younger than\n // `freshAge` (default 1 day). Every user-owned table cascades on delete.\n // Impersonation and last-admin guards live in hooks.before below.\n deleteUser: { enabled: true },\n },\n\n // Advanced options\n advanced: {\n database: {\n generateId: () => createId(),\n },\n },\n\n // Every new session row corresponds to a sign-in (credential or OAuth) —\n // use that as the \"last logged in\" signal rather than session updates,\n // which also fire on cookie-cache refresh / expiry extension.\n databaseHooks: {\n session: {\n create: {\n async after(session, context) {\n // Impersonation sessions (created by the admin plugin's\n // impersonateUser endpoint) also go through session.create —\n // don't let \"an admin looked at this account\" show up as the\n // user's own last login, and log it as an audit event instead.\n const impersonatedBy = (session as { impersonatedBy?: string | null }).impersonatedBy\n if (impersonatedBy) {\n const target = await db\n .select({ email: users.email })\n .from(users)\n .where(eq(users.id, session.userId))\n .limit(1)\n\n await logActivity({\n userId: impersonatedBy,\n action: 'impersonation_started',\n description: `Admin started impersonating ${target[0]?.email ?? session.userId}`,\n metadata: { impersonatedUserId: session.userId },\n })\n return\n }\n\n try {\n await db\n .update(users)\n .set({ lastLoginAt: new Date() })\n .where(eq(users.id, session.userId))\n } catch (error) {\n console.error(\"Failed to update lastLoginAt\", error)\n }\n\n try {\n const headers = context?.headers\n const ipAddress = getClientIp(headers)\n const userAgent = headers?.get('user-agent') ?? null\n // For OAuth, the live referer header on this request is the\n // provider's own callback page (e.g. accounts.google.com), not\n // the page the user actually came from — socialLogin.tsx stashes\n // the real page in a cookie right before the redirect, which\n // survives the round trip since it's set on our own origin.\n // Falls back to the live header for email/password sign-in,\n // where this request *is* the originating request.\n const referrerUrl = context?.getCookie?.(LOGIN_REFERRER_COOKIE)\n || headers?.get('referer')\n || null\n const device = parseUserAgent(userAgent)\n const geo = lookupGeoLocation(ipAddress)\n\n // Every session row for this user, including the one just\n // created — count === 1 means signup just auto-signed them in\n // (better-auth's default), anything higher is a returning login.\n const [{ count }] = await db\n .select({ count: sql<number>`count(*)` })\n .from(sessions)\n .where(eq(sessions.userId, session.userId))\n const isFirstSession = Number(count) <= 1\n\n await logActivity({\n userId: session.userId,\n action: 'login',\n description: isFirstSession\n ? 'New account registered and signed in'\n : 'User logged in',\n ipAddress,\n userAgent,\n referrerUrl,\n os: device.os,\n browser: device.browser,\n deviceType: device.deviceType,\n country: geo.country,\n city: geo.city,\n })\n } catch (error) {\n console.error(\"Failed to log login activity\", error)\n }\n },\n },\n },\n },\n // better-auth's admin plugin ends impersonation by deleting the\n // impersonation session and restoring the admin's original session\n // straight from a signed cookie — it never runs session.create, so\n // there's no databaseHooks entry point to log the stop event from.\n // Reading the session here (before the endpoint deletes it) is the only\n // point where both the admin id and the impersonated user id are still\n // available together.\n hooks: {\n before: createAuthMiddleware(async (ctx) => {\n // Per-device abuse throttle for the two credential entry points.\n // Primarily keyed by the client's FingerprintJS visitorId\n // (x-device-fingerprint header, set in emailPasswordLogin/Signup), but\n // that header is client-supplied and unsigned — omitting it or\n // randomizing it per request bypasses a fingerprint-only check\n // entirely. IP is a lower-ceiling-tolerant backstop (shared behind\n // NAT/CGNAT/VPN, so it uses MAX_IP, not MAX) that still applies when\n // the header is missing or spoofed.\n if (ctx.path === \"/sign-in/email\" || ctx.path === \"/sign-up/email\") {\n const fingerprint = ctx.headers?.get(DEVICE_FINGERPRINT_HEADER)\n const ip = getClientIp(ctx.headers)\n const throttled =\n (fingerprint && (await isDeviceThrottled(fingerprint))) ||\n (ip && (await isDeviceThrottled(`ip:${ip}`, MAX_IP)))\n if (throttled) {\n throw new APIError(\"TOO_MANY_REQUESTS\", {\n message: \"Too many attempts from this device. Try again in a few minutes.\",\n })\n }\n }\n\n // Live kill-switch for the two built-in sign-in methods, on top of\n // the (untouched) provider registration above — lets an admin\n // disable a method from the System Settings page and have it take\n // effect immediately, even for a client that already has the button\n // rendered, instead of only on next deploy.\n if (ctx.path === \"/sign-in/social\") {\n // Scoped to \"google\" specifically since overrides.socialProviders\n // can register other providers (e.g. apple) this flag shouldn't gate.\n if (ctx.body?.provider === \"google\") {\n const flags = await getEffectiveAuthFlags()\n if (!flags.google) {\n throw new APIError(\"FORBIDDEN\", { message: \"Google sign-in is currently disabled.\" })\n }\n }\n return\n }\n\n if (ctx.path === \"/sign-in/email\") {\n const flags = await getEffectiveAuthFlags()\n if (!flags.emailPassword) {\n throw new APIError(\"FORBIDDEN\", { message: \"Email/password sign-in is currently disabled.\" })\n }\n return\n }\n\n // One Tap isn't a separate identity, it's a UI shortcut into the\n // same Google account — its plugin hits its own endpoint entirely\n // (not /sign-in/social), so it needs its own guard, and it needs\n // both flags: Google itself must still be allowed, and the One Tap\n // prompt specifically must be enabled.\n if (ctx.path === \"/one-tap/callback\") {\n const flags = await getEffectiveAuthFlags()\n if (!flags.google || !flags.oneTap) {\n throw new APIError(\"FORBIDDEN\", { message: \"Google One Tap is currently disabled.\" })\n }\n return\n }\n\n if (ctx.path === \"/delete-user\") {\n const current = await getSessionFromCtx(ctx, { disableCookieCache: true })\n if (!current) return // better-auth's own session check rejects it\n // An admin \"viewing as\" a user must not be able to destroy their account.\n if (current.session.impersonatedBy) {\n throw new APIError(\"FORBIDDEN\", { message: \"Stop impersonating before deleting an account.\" })\n }\n // Deleting the last admin would leave nobody able to reach the admin dashboard.\n if ((current.user as { role?: string }).role === \"admin\") {\n const [{ count }] = await db\n .select({ count: sql<number>`count(*)` })\n .from(users)\n .where(eq(users.role, \"admin\"))\n if (Number(count) <= 1) {\n throw new APIError(\"FORBIDDEN\", { message: \"You're the only admin. Promote another user to admin first.\" })\n }\n }\n return\n }\n\n if (ctx.path !== \"/admin/stop-impersonating\") return\n\n const current = await getSessionFromCtx(ctx, { disableCookieCache: true })\n if (current?.session.impersonatedBy) {\n const target = await db\n .select({ email: users.email })\n .from(users)\n .where(eq(users.id, current.session.userId))\n .limit(1)\n\n await logActivity({\n userId: current.session.impersonatedBy,\n action: 'impersonation_stopped',\n description: `Admin stopped impersonating ${target[0]?.email ?? current.session.userId}`,\n metadata: { impersonatedUserId: current.session.userId },\n })\n }\n }),\n after: createAuthMiddleware(async (ctx) => {\n // Passkey add/remove is a security-sensitive change to how the account\n // can be signed into — email the user whenever one lands, the same way\n // new-device sign-ins are surfaced. Best-effort: never disturb the\n // endpoint's own response.\n if (ctx.path === \"/passkey/verify-registration\" || ctx.path === \"/passkey/delete-passkey\") {\n if (ctx.context.returned instanceof APIError) return\n await notifyPasskeyChange(\n ctx,\n ctx.path === \"/passkey/verify-registration\" ? \"added\" : \"removed\",\n )\n return\n }\n\n if (ctx.path !== \"/sign-in/email\" && ctx.path !== \"/sign-up/email\") return\n\n const fingerprint = ctx.headers?.get(DEVICE_FINGERPRINT_HEADER)\n const ip = getClientIp(ctx.headers)\n const ipKey = ip ? `ip:${ip}` : null\n if (!fingerprint && !ipKey) return\n\n const failed = ctx.context.returned instanceof APIError\n const rawEmail = (ctx.body as { email?: unknown } | undefined)?.email\n const meta = {\n ipAddress: ip,\n userAgent: ctx.headers?.get(\"user-agent\") ?? null,\n email: typeof rawEmail === \"string\" ? rawEmail.toLowerCase() : null,\n }\n const keys = [fingerprint, ipKey].filter((k): k is string => !!k)\n\n // Sign-up abuse is mass account creation — the *successful* ones are\n // the problem — so every sign-up from this device counts.\n if (ctx.path === \"/sign-up/email\") {\n await Promise.all(keys.map((key) => recordDeviceAttempt(key, { ...meta, kind: \"signup\" })))\n return\n }\n\n // /sign-in/email: count failures; a success clears the counter.\n // ponytail: a successful sign-in wipes the device's failure budget, so\n // a credential-stuffing hit resets itself — per-outcome counters if\n // that ceiling ever bites.\n if (failed) {\n await Promise.all(keys.map((key) => recordDeviceAttempt(key, { ...meta, kind: \"signin\" })))\n await logFailedLogin(ctx)\n } else {\n await Promise.all(keys.map((key) => clearDeviceThrottle(key)))\n }\n }),\n },\n\n // Base URL for callbacks\n baseURL,\n\n // Secret for signing cookies and tokens\n secret: process.env.AUTH_SECRET!,\n\n // The OAuth `state` is a one-time verification row: the callback consumes\n // and deletes it. When the same callback URL gets hit twice (browser\n // prefetch / bfcache / double nav — common on a repeat Google sign-in\n // where Google auto-redirects with no consent screen), the first hit\n // logs the user in and the second finds no `state` row and throws\n // `please_restart_the_process`. Default sends that to better-auth's bare\n // error page; point it at /login instead, which already bounces an\n // authenticated user straight to their callbackUrl — so the losing race\n // just lands them logged in. See better-auth#5658 / #6544.\n onAPIError: {\n errorURL: \"/login\",\n },\n\n plugins: [\n // Registered for impersonation (auth.api.impersonateUser / stopImpersonating)\n // only — role/ban/delete stay on our own custom routes above. adminRoles\n // matches our existing role column so the plugin's own permission checks\n // line up with hasRole(role, 'admin'). banReason is remapped onto our\n // existing bannedReason column instead of adding a duplicate field.\n adminPlugin({\n adminRoles: [\"admin\"],\n schema: {\n user: {\n fields: {\n banReason: \"bannedReason\",\n },\n },\n },\n }),\n // TOTP second factor + encrypted backup codes. `issuer` is the label\n // shown in the user's authenticator app.\n twoFactor({ issuer: config.APP_NAME }),\n // WebAuthn passkeys (Touch ID / Windows Hello / security keys) as a\n // passwordless sign-in method. rpID must be the bare host and origin\n // the full URL — both derived from baseURL above.\n passkey({\n rpID: new URL(baseURL).hostname,\n rpName: config.APP_NAME,\n origin: baseURL,\n }),\n // checks to see if oneTap is enabled and if google provider is available, then add the oneTap plugin.\n // Keep this spread last: a leading spread turns `plugins` from a tuple into a plain\n // array and better-auth 1.7 then drops plugin fields (e.g. session.impersonatedBy).\n ...(config.AUTH_ENABLE_ONE_TAP && Boolean(socialProviders.google) ? [oneTap()] : []),\n ]\n })\n}\n\n// Lazy: constructing the default instance validates config and throws if no\n// provider is enabled (see the guard above). Building it eagerly at module\n// load would mean a downstream project that only imports `createAuth` to\n// build its *own* customized instance (README §5) still pays that throw —\n// merely importing this module would run it, regardless of whether the\n// consuming project ever touches this default export. Deferring construction\n// to first property access means the throw only fires for code that actually\n// uses the package's own unconfigured `auth` singleton.\nlet _auth: ReturnType<typeof createAuth> | undefined\nfunction getDefaultAuth() {\n if (!_auth) _auth = createAuth()\n return _auth\n}\n\nexport const auth = new Proxy({} as ReturnType<typeof createAuth>, {\n get(_target, prop) {\n const instance = getDefaultAuth()\n const value = Reflect.get(instance, prop)\n return typeof value === \"function\" ? value.bind(instance) : value\n },\n // \"prop\" in auth (e.g. better-auth's toNextJsHandler does `\"handler\" in auth`)\n // must also see the real instance — without this it checks the empty\n // placeholder target and always reports false.\n has(_target, prop) {\n return Reflect.has(getDefaultAuth(), prop)\n },\n ownKeys(_target) {\n return Reflect.ownKeys(getDefaultAuth())\n },\n getOwnPropertyDescriptor(_target, prop) {\n return Reflect.getOwnPropertyDescriptor(getDefaultAuth(), prop)\n },\n})\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { db } from './chunk-
|
|
2
|
-
import { errorRefs } from './chunk-
|
|
1
|
+
import { db } from './chunk-F7CG5CA3.mjs';
|
|
2
|
+
import { errorRefs } from './chunk-TR5XFBTD.mjs';
|
|
3
3
|
import 'server-only';
|
|
4
4
|
import { randomBytes } from 'crypto';
|
|
5
5
|
import { after } from 'next/server';
|
|
@@ -72,5 +72,5 @@ function withActionErrors(action) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export { ActionError, lookupErrorDetail, unexpectedErrorMessage, withActionErrors };
|
|
75
|
-
//# sourceMappingURL=chunk-
|
|
76
|
-
//# sourceMappingURL=chunk-
|
|
75
|
+
//# sourceMappingURL=chunk-6KTSULA5.mjs.map
|
|
76
|
+
//# sourceMappingURL=chunk-6KTSULA5.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/errors.ts"],"names":[],"mappings":";;;;;;;AAQA,IAAM,YAAA,GAAe,kCAAA;AACrB,IAAM,WAAA,GAAc,8BAAA;AACpB,IAAM,iBAAA,GAAoB,GAAA;AAC1B,IAAM,YAAA,GAAe,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,GAAA;AAEzC,SAAS,cAAc,KAAA,EAAwB;AAC7C,EAAA,IAAI,KAAA,YAAiB,KAAA,EAAO,OAAO,KAAA,CAAM,KAAA,IAAS,GAAG,KAAA,CAAM,IAAI,CAAA,EAAA,EAAK,KAAA,CAAM,OAAO,CAAA,CAAA;AACjF,EAAA,IAAI;AACF,IAAA,OAAO,IAAA,CAAK,SAAA,CAAU,KAAA,EAAO,IAAA,EAAM,CAAC,CAAA;AAAA,EACtC,CAAA,CAAA,OAAQ,CAAA,EAAA;AACN,IAAA,OAAO,OAAO,KAAK,CAAA;AAAA,EACrB;AACF;AAIA,SAAS,WAAA,CAAY,GAAA,EAAa,OAAA,EAAiB,KAAA,EAAgB;AACjE,EAAA,MAAM,OAAO,YAAY;AACvB,IAAA,IAAI;AACF,MAAA,MAAM,EAAA,CAAG,MAAA,CAAO,SAAS,CAAA,CAAE,MAAA,CAAO;AAAA,QAChC,GAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAQ,aAAA,CAAc,KAAK,CAAA,CAAE,KAAA,CAAM,GAAG,iBAAiB;AAAA,OACxD,CAAA;AAED,MAAA,MAAM,EAAA,CAAG,MAAA,CAAO,SAAS,CAAA,CAAE,MAAM,EAAA,CAAG,SAAA,CAAU,SAAA,EAAW,IAAI,KAAK,IAAA,CAAK,GAAA,EAAI,GAAI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AA,KACjB,MAAA,CAAO,WAAW,eAAe,CAAA,IAAK,MAAA,CAAO,UAAA,CAAW,0BAA0B,CAAA,CAAA;AAEvF;AAGO,SAAS,iBACd,MAAA,EAC6C;AAC7C,EAAA,OAAO,UAAU,IAAA,KAAyC;AACxD,IAAA,IAAI;AACF,MAAA,OAAO,EAAE,IAAI,IAAA,EAAM,IAAA,EAAM,MAAM,MAAA,CAAO,GAAG,IAAI,CAAA,EAAE;AAAA,IACjD,SAAS,KAAA,EAAO;AACd,MAAA,IAAI,iBAAiB,WAAA,EAAa;AAChC,QAAA,OAAO,EAAE,EAAA,EAAI,KAAA,EAAO,OAAA,EAAS,MAAM,OAAA,EAAQ;AAAA,MAC7C;AACA,MAAA,IAAI,2BAAA,CAA4B,KAAK,CAAA,EAAG;AACtC,QAAA,MAAM,KAAA;AAAA,MACR;AAGA,MAAA,OAAO,EAAE,EAAA,EAAI,KAAA,EAAO,OAAA,EAAS,sBAAA,CAAuB,KAAK,CAAA,EAAE;AAAA,IAC7D;AAAA,EACF,CAAA;AACF","file":"chunk-6KTSULA5.mjs","sourcesContent":["import \"server-only\"\nimport { randomBytes } from \"node:crypto\"\nimport { after } from \"next/server\"\nimport { eq, lt } from \"drizzle-orm\"\nimport { db } from \"../server/db\"\nimport { errorRefs } from \"../server/db/schema\"\n\n// No 0/O/1/I so a user can read a ref back without mix-ups.\nconst REF_ALPHABET = \"23456789ABCDEFGHJKLMNPQRSTUVWXYZ\"\nconst REF_PATTERN = /\\(ref: ([2-9A-HJ-NP-Z]{6})\\)/\nconst DETAIL_MAX_LENGTH = 8000\nconst RETENTION_MS = 30 * 24 * 60 * 60 * 1000\n\nfunction describeError(error: unknown): string {\n if (error instanceof Error) return error.stack || `${error.name}: ${error.message}`\n try {\n return JSON.stringify(error, null, 2)\n } catch {\n return String(error)\n }\n}\n\n// Saves the detail so a later feedback report can carry it. Runs after the\n// response when inside a request (after()), and never fails the caller.\nfunction storeDetail(ref: string, message: string, error: unknown) {\n const save = async () => {\n try {\n await db.insert(errorRefs).values({\n ref,\n message,\n detail: describeError(error).slice(0, DETAIL_MAX_LENGTH),\n })\n // ponytail: prune on insert; a scheduled cleanup if error volume ever gets high.\n await db.delete(errorRefs).where(lt(errorRefs.createdAt, new Date(Date.now() - RETENTION_MS)))\n } catch (storeError) {\n console.error(`[error ref ${ref}] could not store error detail`, storeError)\n }\n }\n try {\n after(save)\n } catch {\n void save() // outside a request scope (e.g. a script)\n }\n}\n\n/** The stored technical detail for the ref inside a user-facing error message, if any. */\nexport async function lookupErrorDetail(text: string): Promise<string | null> {\n const ref = text.match(REF_PATTERN)?.[1]\n if (!ref) return null\n const [row] = await db\n .select({ detail: errorRefs.detail })\n .from(errorRefs)\n .where(eq(errorRefs.ref, ref))\n .limit(1)\n return row?.detail ?? null\n}\n\n/**\n * Logs an unexpected error under a short reference and returns the message to\n * show instead, e.g. \"Failed to update role (ref: K7Q2PX)\". The user, and any\n * feedback report they send, only ever get the ref. The error itself goes to\n * the server log (\"error ref K7Q2PX\") and the error_refs table, from which the\n * feedback route attaches it to reports sent to Discord/email.\n */\nexport function unexpectedErrorMessage(\n error: unknown,\n message = \"Something went wrong. Please try again.\"\n): string {\n const ref = Array.from(randomBytes(6), (b) => REF_ALPHABET[b % REF_ALPHABET.length]).join(\"\")\n console.error(`[error ref ${ref}] ${message}`, error)\n storeDetail(ref, message, error)\n return `${message} (ref: ${ref})`\n}\n\n/**\n * Throw this for messages that are safe to show to the end user (validation,\n * permission, and state-conflict errors). Anything else thrown inside a\n * `withActionErrors`-wrapped action is logged server-side and replaced with a\n * generic message carrying an error ref.\n */\nexport class ActionError extends Error {}\n\nexport type ActionResult<T> =\n | { ok: true; data: T }\n | { ok: false; message: string }\n\nfunction isFrameworkControlFlowError(error: unknown): boolean {\n const digest = (error as { digest?: unknown } | null)?.digest\n return (\n typeof digest === \"string\" &&\n (digest.startsWith(\"NEXT_REDIRECT\") || digest.startsWith(\"NEXT_HTTP_ERROR_FALLBACK\"))\n )\n}\n\n/** Wraps a server action so it returns an ActionResult instead of throwing. */\nexport function withActionErrors<Args extends unknown[], T>(\n action: (...args: Args) => Promise<T>\n): (...args: Args) => Promise<ActionResult<T>> {\n return async (...args: Args): Promise<ActionResult<T>> => {\n try {\n return { ok: true, data: await action(...args) }\n } catch (error) {\n if (error instanceof ActionError) {\n return { ok: false, message: error.message }\n }\n if (isFrameworkControlFlowError(error)) {\n throw error\n }\n // Returned, not thrown: Next.js replaces thrown server-action messages\n // in production, which would drop the ref.\n return { ok: false, message: unexpectedErrorMessage(error) }\n }\n }\n}\n"]}
|
|
@@ -50,12 +50,13 @@ function formatLocation({ country, city }) {
|
|
|
50
50
|
var WINDOW_MS = 15 * 60 * 1e3;
|
|
51
51
|
var MAX = 10;
|
|
52
52
|
var MAX_IP = MAX * 3;
|
|
53
|
+
var RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
53
54
|
function isOverLimit(row, now, max = MAX) {
|
|
54
55
|
if (!row) return false;
|
|
55
56
|
if (now - row.windowStart.getTime() >= WINDOW_MS) return false;
|
|
56
57
|
return row.count >= max;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
export { MAX_IP, WINDOW_MS, formatDeviceInfo, formatLocation, getClientIp, isOverLimit, lookupGeoLocation, parseUserAgent };
|
|
60
|
-
//# sourceMappingURL=chunk-
|
|
61
|
-
//# sourceMappingURL=chunk-
|
|
60
|
+
export { MAX_IP, RETENTION_MS, WINDOW_MS, formatDeviceInfo, formatLocation, getClientIp, isOverLimit, lookupGeoLocation, parseUserAgent };
|
|
61
|
+
//# sourceMappingURL=chunk-6OAHCEDJ.mjs.map
|
|
62
|
+
//# sourceMappingURL=chunk-6OAHCEDJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/request-info.ts","../lib/auth-throttle-limits.ts"],"names":[],"mappings":";;;;;AAIA,IAAM,YAAA,GAAe,IAAI,IAAA,CAAK,YAAA,CAAa,CAAC,IAAI,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K;AAC5B,IAAM,GAAA,GAAM,EAAA;AAQZ,IAAM,SAAS,GAAA,GAAM;AAKrB,IAAM,YAAA,GAAe,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK;AAKzC,SAAS,WAAA,CACd,GAAA,EACA,GAAA,EACA,GAAA,GAAc,GAAA,EACL;AACT,EAAA,IAAI,CAAC,KAAK,OAAO,KAAA;AACjB,EAAA,IAAI,MAAM,GAAA,CAAI,WAAA,CAAY,OAAA,EAAQ,IAAK,WAAW,OAAO,KAAA;AACzD,EAAA,OAAO,IAAI,KAAA,IAAS,GAAA;AACtB","file":"chunk-6OAHCEDJ.mjs","sourcesContent":["import \"server-only\"\nimport { UAParser } from \"ua-parser-js\"\nimport geoip from \"geoip-lite\"\n\nconst countryNames = new Intl.DisplayNames([\"en\"], { type: \"region\" })\n\nexport type DeviceType = \"desktop\" | \"mobile\" | \"tablet\"\n\nexport interface DeviceInfo {\n os: string | null\n browser: string | null\n deviceType: DeviceType\n}\n\nexport interface GeoInfo {\n country: string | null\n city: string | null\n}\n\n/**\n * First address in X-Forwarded-For is the original client — everything after\n * is intermediate proxies. Falls back to null (e.g. local dev with no proxy).\n */\nexport function getClientIp(headers: Headers | undefined | null): string | null {\n const forwardedFor = headers?.get(\"x-forwarded-for\")\n if (forwardedFor) return forwardedFor.split(\",\")[0].trim()\n\n return headers?.get(\"x-real-ip\") ?? null\n}\n\nexport function parseUserAgent(userAgent: string | null | undefined): DeviceInfo {\n if (!userAgent) {\n return { os: null, browser: null, deviceType: \"desktop\" }\n }\n\n const { os, browser, device } = new UAParser(userAgent).getResult()\n\n return {\n os: os.name ? [os.name, os.version].filter(Boolean).join(\" \") : null,\n browser: browser.name ?? null,\n deviceType: device.type === \"mobile\" || device.type === \"tablet\" ? device.type : \"desktop\",\n }\n}\n\n/**\n * Offline lookup (geoip-lite ships its own IP-range database, no network\n * call) — resolves to nulls for private/local addresses like 127.0.0.1.\n */\nexport function lookupGeoLocation(ipAddress: string | null | undefined): GeoInfo {\n if (!ipAddress) return { country: null, city: null }\n\n const geo = geoip.lookup(ipAddress)\n if (!geo) return { country: null, city: null }\n\n let country: string | null = geo.country || null\n if (country) {\n try {\n country = countryNames.of(country) ?? country\n } catch {\n // Unrecognized region code — keep the raw code rather than losing it.\n }\n }\n\n return { country, city: geo.city || null }\n}\n\nexport function formatDeviceInfo({ os, browser, deviceType }: DeviceInfo): string {\n const label = [browser, os].filter(Boolean).join(\" on \")\n const typeLabel = deviceType === \"mobile\" ? \"Mobile\" : deviceType === \"tablet\" ? \"Tablet\" : \"Desktop\"\n\n return label ? `${label} · ${typeLabel}` : `Unknown device · ${typeLabel}`\n}\n\nexport function formatLocation({ country, city }: GeoInfo): string {\n if (!country && !city) return \"Unknown\"\n\n return [city, country].filter(Boolean).join(\", \")\n}\n","// Pure throttle policy — no DB, no `server-only`, so it stays unit-testable.\n// Consumed by lib/auth-throttle.ts (the DB plumbing) and its test.\n\n// Tune per deployment, or lift to env vars if you need it configurable.\nexport const WINDOW_MS = 15 * 60 * 1000 // how long attempts accumulate\nexport const MAX = 10 // failed sign-ins / sign-ups per window before a 429, per fingerprint\n\n// Backstop cap keyed by IP instead of fingerprint — the fingerprint header is\n// client-supplied and unsigned, so it's trivial to omit or randomize per\n// request (see server/auth.ts before-hook). Higher than MAX because an IP can\n// be shared behind NAT/CGNAT/VPN.\n// ponytail: flat multiplier, not a real per-deployment tuning — revisit if\n// legitimate shared-IP traffic ever gets caught in it.\nexport const MAX_IP = MAX * 3\n\n// Rows untouched this long are deleted (lib/auth-throttle.ts). They hold IP,\n// user agent and the last email typed — often for people with no account — so\n// GDPR storage limitation says don't keep them past their use.\nexport const RETENTION_MS = 30 * 24 * 60 * 60 * 1000\n\n// A row whose window has already elapsed counts as \"no row\" — it resets on\n// the next attempt (see recordDeviceAttempt), so the device isn't blocked in\n// the meantime.\nexport function isOverLimit(\n row: { count: number; windowStart: Date } | undefined,\n now: number,\n max: number = MAX,\n): boolean {\n if (!row) return false\n if (now - row.windowStart.getTime() >= WINDOW_MS) return false\n return row.count >= max\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { db } from './chunk-
|
|
2
|
-
import { systemSettings, DEFAULT_MAINTENANCE_EXEMPT_PATHS } from './chunk-
|
|
1
|
+
import { db } from './chunk-F7CG5CA3.mjs';
|
|
2
|
+
import { systemSettings, DEFAULT_MAINTENANCE_EXEMPT_PATHS } from './chunk-TR5XFBTD.mjs';
|
|
3
3
|
import { config } from './chunk-TMJYAOC2.mjs';
|
|
4
4
|
import { __spreadProps, __spreadValues } from './chunk-3465SI5N.mjs';
|
|
5
5
|
import 'server-only';
|
|
@@ -19,6 +19,7 @@ function fallbackSettings() {
|
|
|
19
19
|
authEnableOneTap: config.AUTH_ENABLE_ONE_TAP,
|
|
20
20
|
enableSessionRevocation: config.ENABLE_SESSION_REVOCATION,
|
|
21
21
|
feedbackAttachErrors: true,
|
|
22
|
+
consentRequired: null,
|
|
22
23
|
updatedAt: /* @__PURE__ */ new Date(0),
|
|
23
24
|
updatedBy: null
|
|
24
25
|
};
|
|
@@ -68,6 +69,10 @@ async function getEffectiveAuthFlags() {
|
|
|
68
69
|
oneTap: config.AUTH_ENABLE_ONE_TAP && settings.authEnableOneTap
|
|
69
70
|
};
|
|
70
71
|
}
|
|
72
|
+
function isConsentRequired(settings) {
|
|
73
|
+
var _a;
|
|
74
|
+
return (_a = settings.consentRequired) != null ? _a : process.env.NEXT_PUBLIC_COOKIE_BANNER !== "false";
|
|
75
|
+
}
|
|
71
76
|
function getConfiguredAuthFlags() {
|
|
72
77
|
return {
|
|
73
78
|
google: config.AUTH_ENABLE_GOOGLE,
|
|
@@ -76,6 +81,6 @@ function getConfiguredAuthFlags() {
|
|
|
76
81
|
};
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
export { getConfiguredAuthFlags, getEffectiveAuthFlags, getSystemSettings, invalidateSystemSettingsCache, updateSystemSettings };
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
81
|
-
//# sourceMappingURL=chunk-
|
|
84
|
+
export { getConfiguredAuthFlags, getEffectiveAuthFlags, getSystemSettings, invalidateSystemSettingsCache, isConsentRequired, updateSystemSettings };
|
|
85
|
+
//# sourceMappingURL=chunk-F776DQAM.mjs.map
|
|
86
|
+
//# sourceMappingURL=chunk-F776DQAM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/settings-queries.ts"],"names":[],"mappings":";;;;;;;AAOA,IAAM,eAAA,GAAkB,SAAA;AAKxB,IAAM,YAAA,GAAe,GAAA;AAIrB,IAAI,MAAA,GAA8D,IAAA;AAKlE,SAAS,gBAAA,GAAmC;AAC1C,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,eAAA;AAAA,IACJ,eAAA,EAAiB,KAAA;AAAA,IACjB,kBAAA,EAAoB,IAAA;AAAA,IACpB,sBAAA,EAAwB,gCAAA;AAAA,IACxB,kBAAkB,MAAA,CAAO,kBAAA;AAAA,IACzB,yBAAyB,MAAA,CAAO,0BAAA;AAAA,IAChC,kBAAkB,MAAA,CAAO,mBAAA;AAAA,IACzB,yBAAyB,MAAA,CAAO,yBAAA;AAAA,IAChC,oBAAA,EAAsB,IAAA;AAAA,IACtB,eAAA,EAAiB,IAAA;AAAA,IACjB,SAAA,kBAAW,IAAI,IAAA,CAAK,CAAC,CAAA;AAAA,IACrB,SAAA,EAAW;AAAA,GACb;AACF;AAEA,eAAe,UAAA,GAAsC;AAtCrD,EAAA,IAAA,EAAA;AAuCE,EAAA,MAAM,WAAW,MAAM,EAAA,CACpB,MAAA,EAAO,CACP,KAAK,cAAc,CAAA,CACnB,KAAA,CAAM,EAAA,CAAG,eAAe,EAAA,EAAI,eAAe,CAAC,CAAA,CAC5C,MAAM,CAAC,CAAA;AACV,EAAA,IAAI,QAAA,CAAS,CAAC,CAAA,EAAG,OAAO,SAAS,CAAC,CAAA;AAMlC,EAAA,MAAM,SAAS,MAAM,EAAA,CAClB,MA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EAAA,MAAM,UAAA,EAAW;AAEjB,EAAA,MAAM,CAAC,OAAO,CAAA,GAAI,MAAM,EAAA,CACrB,MAAA,CAAO,cAAc,CAAA,CACrB,GAAA,CAAI,aAAA,CAAA,cAAA,CAAA,EAAA,EAAK,KAAA,CAAA,EAAL,EAAY,SAAA,sBAAe,IAAA,EAAK,EAAG,SAAA,EAAU,CAAC,CAAA,CAClD,KAAA,CAAM,EAAA,CAAG,cAAA,CAAe,EAAA,EAAI,eAAe,CAAC,CAAA,CAC5C,SAAA,EAAU;AAEb,EAAA,6BAAA,EAA8B;AAC9B,EAAA,OAAO,OAAA;AACT;AAKA,eAAsB,qBAAA,GAAwB;AAC5C,EAAA,MAAM,QAAA,GAAW,MAAM,iBAAA,EAAkB;AACzC,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,MAAA,CAAO,kBAAA,IAAsB,QAAA,CAAS,gBAAA;AAAA,IAC9C,aAAA,EAAe,MAAA,CAAO,0BAAA,IAA8B,QAAA,CAAS,uBAAA;AAAA,IAC7D,MAAA,EAAQ,MAAA,CAAO,mBAAA,IAAuB,QAAA,CAAS;AAAA,GACjD;AACF;AAIO,SAAS,kBAAkB,QAAA,EAA4D;AAhI9F,EAAA,IAAA,EAAA;AAiIE,EAAA,OAAA,CAAO,EAAA,GAAA,QAAA,CAAS,eAAA,KAAT,IAAA,GAAA,EAAA,GAA4B,OAAA,CAAQ,IAAI,yBAAA,KAA8B,OAAA;AAC/E;AAMO,SAAS,sBAAA,GAAyB;AACvC,EAAA,OAAO;AAAA,IACL,QAAQ,MAAA,CAAO,kBAAA;AAAA,IACf,eAAe,MAAA,CAAO,0BAAA;AAAA,IACtB,QAAQ,MAAA,CAAO;AAAA,GACjB;AACF","file":"chunk-F776DQAM.mjs","sourcesContent":["import \"server-only\"\nimport { db } from \"../server/db\"\nimport { systemSettings } from \"../server/db/schema\"\nimport { config } from \"../config/env\"\nimport { eq } from \"drizzle-orm\"\nimport { DEFAULT_MAINTENANCE_EXEMPT_PATHS } from \"./maintenance\"\n\nconst SETTINGS_ROW_ID = \"default\"\n// Short TTL: cheap reads (no DB round trip on every request), while an\n// admin's change is guaranteed live within this window even for a reader\n// that isn't the one who just saved (invalidateSystemSettingsCache() makes\n// it instant for that request's own process).\nconst CACHE_TTL_MS = 10_000\n\nexport type SystemSettings = typeof systemSettings.$inferSelect\n\nlet cached: { value: SystemSettings; expiresAt: number } | null = null\n\n// Fail-open shape if the DB is unreachable: auth flags fall back to their\n// config/env.ts defaults (unchanged behavior), maintenance mode is always\n// off — a DB hiccup must never lock out the whole site, including admins.\nfunction fallbackSettings(): SystemSettings {\n return {\n id: SETTINGS_ROW_ID,\n maintenanceMode: false,\n maintenanceMessage: null,\n maintenanceExemptPaths: DEFAULT_MAINTENANCE_EXEMPT_PATHS,\n authEnableGoogle: config.AUTH_ENABLE_GOOGLE,\n authEnableEmailPassword: config.AUTH_ENABLE_EMAIL_PASSWORD,\n authEnableOneTap: config.AUTH_ENABLE_ONE_TAP,\n enableSessionRevocation: config.ENABLE_SESSION_REVOCATION,\n feedbackAttachErrors: true,\n consentRequired: null,\n updatedAt: new Date(0),\n updatedBy: null,\n }\n}\n\nasync function loadOrSeed(): Promise<SystemSettings> {\n const existing = await db\n .select()\n .from(systemSettings)\n .where(eq(systemSettings.id, SETTINGS_ROW_ID))\n .limit(1)\n if (existing[0]) return existing[0]\n\n // Lazy-seed on first read, from the *current* env config — not the\n // schema's hardcoded column defaults — so turning this feature on never\n // silently flips an already-deployed flag (e.g. a prod deploy that\n // already set AUTH_ENABLE_GOOGLE=false).\n const seeded = await db\n .insert(systemSettings)\n .values({\n id: SETTINGS_ROW_ID,\n maintenanceMode: false,\n authEnableGoogle: config.AUTH_ENABLE_GOOGLE,\n authEnableEmailPassword: config.AUTH_ENABLE_EMAIL_PASSWORD,\n authEnableOneTap: config.AUTH_ENABLE_ONE_TAP,\n enableSessionRevocation: config.ENABLE_SESSION_REVOCATION,\n })\n .onConflictDoNothing()\n .returning()\n\n if (seeded[0]) return seeded[0]\n\n // Lost the seed race to a concurrent first-reader.\n const retry = await db\n .select()\n .from(systemSettings)\n .where(eq(systemSettings.id, SETTINGS_ROW_ID))\n .limit(1)\n return retry[0] ?? fallbackSettings()\n}\n\nexport async function getSystemSettings(): Promise<SystemSettings> {\n const now = Date.now()\n if (cached && cached.expiresAt > now) return cached.value\n\n try {\n const value = await loadOrSeed()\n cached = { value, expiresAt: now + CACHE_TTL_MS }\n return value\n } catch (error) {\n console.error(\"Failed to load system settings, failing open:\", error)\n return fallbackSettings() // not cached — retry next request\n }\n}\n\nexport function invalidateSystemSettingsCache() {\n cached = null\n}\n\nexport type SystemSettingsPatch = Partial<Pick<SystemSettings,\n | 'maintenanceMode' | 'maintenanceMessage' | 'maintenanceExemptPaths'\n | 'authEnableGoogle' | 'authEnableEmailPassword' | 'authEnableOneTap'\n | 'enableSessionRevocation' | 'feedbackAttachErrors' | 'consentRequired'\n>>\n\nexport async function updateSystemSettings(\n patch: SystemSettingsPatch,\n updatedBy: string\n): Promise<SystemSettings> {\n await loadOrSeed() // ensure the row exists even if nobody's read it yet\n\n const [updated] = await db\n .update(systemSettings)\n .set({ ...patch, updatedAt: new Date(), updatedBy })\n .where(eq(systemSettings.id, SETTINGS_ROW_ID))\n .returning()\n\n invalidateSystemSettingsCache()\n return updated\n}\n\n// Effective auth-method visibility = deploy-time \"configured\" (env, decides\n// whether the provider is even registered with better-auth — see\n// server/auth.ts's createAuth()) AND runtime \"offered\" (this DB flag).\nexport async function getEffectiveAuthFlags() {\n const settings = await getSystemSettings()\n return {\n google: config.AUTH_ENABLE_GOOGLE && settings.authEnableGoogle,\n emailPassword: config.AUTH_ENABLE_EMAIL_PASSWORD && settings.authEnableEmailPassword,\n oneTap: config.AUTH_ENABLE_ONE_TAP && settings.authEnableOneTap,\n }\n}\n\n// Consent mode: the admin's choice if they've made one, else the\n// NEXT_PUBLIC_COOKIE_BANNER default (banner on unless it's \"false\").\nexport function isConsentRequired(settings: Pick<SystemSettings, 'consentRequired'>): boolean {\n return settings.consentRequired ?? process.env.NEXT_PUBLIC_COOKIE_BANNER !== \"false\"\n}\n\n// The env-only half of the AND above. The System Settings page needs this\n// to explain *why* a toggle it controls isn't taking effect — flipping the\n// DB flag on can't do anything if the env var for that method is off, so\n// the UI should say so instead of looking like a silent no-op.\nexport function getConfiguredAuthFlags() {\n return {\n google: config.AUTH_ENABLE_GOOGLE,\n emailPassword: config.AUTH_ENABLE_EMAIL_PASSWORD,\n oneTap: config.AUTH_ENABLE_ONE_TAP,\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { schema_exports } from './chunk-
|
|
1
|
+
import { schema_exports } from './chunk-TR5XFBTD.mjs';
|
|
2
2
|
import { config } from './chunk-TMJYAOC2.mjs';
|
|
3
3
|
import 'server-only';
|
|
4
4
|
import { neon } from '@neondatabase/serverless';
|
|
@@ -26,5 +26,5 @@ if (config.DB_DRIVER === "pg") {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export { db };
|
|
29
|
-
//# sourceMappingURL=chunk-
|
|
30
|
-
//# sourceMappingURL=chunk-
|
|
29
|
+
//# sourceMappingURL=chunk-F7CG5CA3.mjs.map
|
|
30
|
+
//# sourceMappingURL=chunk-F7CG5CA3.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../server/db/index.ts"],"names":["drizzlePg","drizzle"],"mappings":";;;;;;;;AAoBA,IAAI;AAGJ,IAAI,MAAA,CAAO,cAAc,IAAA,EAAM;AAC7B,EAAA,MAAM,IAAA,GAAO,IAAI,IAAA,CAAK;AAAA,IACpB,kBAAkB,MAAA,CAAO,YAAA;AAAA,IACzB,KAAK,MAAA,CAAO,YAAA,GAAe,EAAE,kBAAA,EAAoB,OAAM,GAAI;AAAA,GAC5D,CAAA;AACD,EAAA,EAAA,GAAKA,QAAU,IAAA,EAAM;AAAA,IACnB,MAAA,EAAA,cAAA;AAAA,IACA,MAAA,EAAQ;AA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AI,yDAAA,EAA2D,MAAA,CAAO,SAAS,CAAA;AACzF","file":"chunk-F7CG5CA3.mjs","sourcesContent":["import 'server-only';\n\n// neon-http driver for production\nimport { neon } from '@neondatabase/serverless';\nimport { drizzle } from 'drizzle-orm/neon-http';\n\n// postgres driver for local development\nimport { drizzle as drizzlePg } from 'drizzle-orm/node-postgres';\nimport { Pool } from 'pg';\n\nimport * as schema from './schema';\nimport { config } from '../../config/env';\n\n// Import the query builder\nimport { PostgresJsDatabase } from 'drizzle-orm/postgres-js';\nimport { NeonHttpDatabase } from 'drizzle-orm/neon-http';\n\ntype DrizzleNeon = NeonHttpDatabase<typeof schema>;\ntype DrizzlePg = PostgresJsDatabase<typeof schema>;\n\nlet db: DrizzleNeon | DrizzlePg\n\n\nif (config.DB_DRIVER === 'pg') {\n const pool = new Pool({\n connectionString: config.DATABASE_URL!,\n ssl: config.DATABASE_SSL ? { rejectUnauthorized: false } : undefined,\n });\n db = drizzlePg(pool, {\n schema,\n logger: true,\n });\n\n console.log('🟡 Using PostgreSQL (pg) driver');\n\n} else if (config.DB_DRIVER === 'neon') {\n const sql = neon(config.DATABASE_URL!);\n db = drizzle(sql, { schema, logger: true });\n\n console.log('🟢 Using Neon (HTTP) driver');\n\n} else {\n console.log('Database connection not established, unknown DB_DRIVER:', config.DB_DRIVER);\n}\n// Note: In production, you might want to disable logging or use a more sophisticated logger.\n\nexport { db }"]}
|