@payez/next-mvp 4.1.20 → 4.4.0
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/POST-INSTALL.md +408 -0
- package/README.md +7 -0
- package/dist/api-handlers/account/recovery/initiate.js +35 -2
- package/dist/api-handlers/account/recovery/send-code.d.ts +0 -33
- package/dist/api-handlers/account/recovery/send-code.js +35 -2
- package/dist/api-handlers/account/recovery/verify-code.d.ts +0 -33
- package/dist/api-handlers/account/recovery/verify-code.js +35 -2
- package/dist/api-handlers/account/reset-password.js +35 -2
- package/dist/api-handlers/account/validate-password.js +21 -3
- package/dist/api-handlers/admin/analytics.js +2 -1
- package/dist/api-handlers/admin/audit.js +2 -1
- package/dist/api-handlers/admin/sessions.js +2 -1
- package/dist/api-handlers/admin/stats.js +2 -1
- package/dist/api-handlers/admin/users.js +2 -1
- package/dist/api-handlers/admin/vibe-data.js +2 -1
- package/dist/api-handlers/auth/jwks.js +10 -0
- package/dist/api-handlers/auth/login.js +5 -2
- package/dist/api-handlers/auth/passkey-signin.js +16 -1
- package/dist/api-handlers/auth/refresh.d.ts +23 -3
- package/dist/api-handlers/auth/refresh.js +107 -16
- package/dist/api-handlers/auth/signout.js +3 -2
- package/dist/api-handlers/auth/verify-code.js +5 -2
- package/dist/api-handlers/session/viability.js +27 -1
- package/dist/api-handlers/test/force-expire.d.ts +29 -15
- package/dist/api-handlers/test/force-expire.js +109 -14
- package/dist/auth/better-auth.d.ts +263 -6
- package/dist/auth/better-auth.js +437 -59
- package/dist/auth/utils/idp-client.js +1 -1
- package/dist/client/AuthContext.js +49 -17
- package/dist/components/account/UserAvatarMenu.js +12 -0
- package/dist/components/auth/ModeAwareLoginPage.js +10 -8
- package/dist/components/auth/ModeAwareSignupPage.js +5 -2
- package/dist/components/auth/TraditionalAuthSection.js +5 -1
- package/dist/hooks/useAuthSettings.js +14 -2
- package/dist/hooks/usePublicAuthSettings.d.ts +2 -2
- package/dist/hooks/usePublicAuthSettings.js +28 -14
- package/dist/lib/client-key.d.ts +61 -0
- package/dist/lib/client-key.js +72 -0
- package/dist/lib/demo-mode.js +2 -1
- package/dist/lib/ensure-fresh-access-token.js +12 -1
- package/dist/lib/idp-client-config.d.ts +25 -2
- package/dist/lib/idp-client-config.js +381 -36
- package/dist/lib/idp-fetch.d.ts +2 -0
- package/dist/lib/idp-fetch.js +31 -1
- package/dist/lib/idp-url-guard.d.ts +29 -0
- package/dist/lib/idp-url-guard.js +38 -0
- package/dist/lib/redis.js +77 -5
- package/dist/lib/session-cookie-shape.d.ts +69 -0
- package/dist/lib/session-cookie-shape.js +126 -0
- package/dist/lib/session-store.d.ts +35 -2
- package/dist/lib/session-store.js +135 -4
- package/dist/lib/single-flight.d.ts +35 -0
- package/dist/lib/single-flight.js +30 -0
- package/dist/lib/token-lifecycle.js +12 -0
- package/dist/middleware/create-middleware.js +12 -0
- package/dist/models/SessionModel.d.ts +41 -0
- package/dist/models/SessionModel.js +9 -0
- package/dist/pages/admin-login/page.d.ts +1 -1
- package/dist/pages/admin-login/page.js +5 -41
- package/dist/pages/security/EnhancedSecurityPage.d.ts +35 -1
- package/dist/pages/security/EnhancedSecurityPage.js +42 -2
- package/dist/pages/security/index.d.ts +1 -0
- package/dist/pages/security/index.js +3 -0
- package/dist/pages/test-env/EmergencyLogoutPage.d.ts +17 -5
- package/dist/pages/test-env/EmergencyLogoutPage.js +17 -5
- package/dist/pages/test-env/JwtInspectPage.d.ts +30 -5
- package/dist/pages/test-env/JwtInspectPage.js +166 -7
- package/dist/pages/test-env/RefreshTokenPage.d.ts +22 -6
- package/dist/pages/test-env/RefreshTokenPage.js +22 -6
- package/dist/pages/test-env/TestEnvPage.d.ts +16 -4
- package/dist/pages/test-env/TestEnvPage.js +16 -4
- package/dist/pages/test-env/guarded.d.ts +4 -0
- package/dist/pages/test-env/guarded.js +86 -0
- package/dist/pages/test-env/index.d.ts +50 -7
- package/dist/pages/test-env/index.js +58 -12
- package/dist/routes/auth/logout.js +3 -2
- package/dist/routes/auth/refresh.js +27 -1
- package/dist/routes/auth/session.d.ts +12 -3
- package/dist/routes/auth/session.js +92 -9
- package/dist/routes/auth/settings.d.ts +34 -4
- package/dist/routes/auth/settings.js +87 -33
- package/dist/routes/auth/viability.d.ts +1 -1
- package/dist/routes/auth/viability.js +122 -11
- package/dist/server/auth-guard.js +22 -15
- package/dist/server/auth.d.ts +170 -4
- package/dist/server/auth.js +42 -75
- package/dist/server/decode-session.js +84 -10
- package/dist/types/auth.d.ts +18 -0
- package/package.json +969 -958
- package/scripts/check-internal-url-usage.sh +73 -73
- package/scripts/check-publish-health.mjs +120 -0
- package/scripts/dev-broker.ps1 +71 -6
- package/scripts/print-client-config.mjs +162 -0
- package/scripts/server-only-stub.cjs +4 -0
- package/src/api-handlers/account/recovery/initiate.ts +35 -2
- package/src/api-handlers/account/recovery/send-code.ts +36 -2
- package/src/api-handlers/account/recovery/verify-code.ts +36 -2
- package/src/api-handlers/account/reset-password.ts +35 -2
- package/src/api-handlers/account/validate-password.ts +22 -3
- package/src/api-handlers/admin/analytics.ts +2 -1
- package/src/api-handlers/admin/audit.ts +2 -1
- package/src/api-handlers/admin/sessions.ts +2 -1
- package/src/api-handlers/admin/stats.ts +2 -1
- package/src/api-handlers/admin/users.ts +2 -1
- package/src/api-handlers/admin/vibe-data.ts +2 -1
- package/src/api-handlers/auth/jwks.ts +10 -0
- package/src/api-handlers/auth/login.ts +5 -2
- package/src/api-handlers/auth/passkey-signin.ts +112 -98
- package/src/api-handlers/auth/refresh.ts +112 -15
- package/src/api-handlers/auth/signout.ts +4 -3
- package/src/api-handlers/auth/verify-code.ts +5 -2
- package/src/api-handlers/mfa/backup-code-verify.ts +175 -175
- package/src/api-handlers/mfa/backup-codes.ts +41 -41
- package/src/api-handlers/mfa/methods.ts +46 -46
- package/src/api-handlers/mfa/totp-confirm.ts +42 -42
- package/src/api-handlers/mfa/totp-enroll.ts +42 -42
- package/src/api-handlers/passkeys/list.ts +31 -31
- package/src/api-handlers/passkeys/manage.ts +54 -54
- package/src/api-handlers/passkeys/register-options.ts +42 -42
- package/src/api-handlers/passkeys/register-verify.ts +41 -41
- package/src/api-handlers/session/viability.ts +29 -1
- package/src/api-handlers/test/force-expire.ts +118 -13
- package/src/auth/better-auth.ts +486 -51
- package/src/auth/utils/idp-client.ts +1 -1
- package/src/client/AuthContext.tsx +55 -19
- package/src/components/account/UserAvatarMenu.tsx +11 -0
- package/src/components/auth/ModeAwareLoginPage.tsx +40 -49
- package/src/components/auth/ModeAwareSignupPage.tsx +5 -2
- package/src/components/auth/TraditionalAuthSection.tsx +5 -1
- package/src/hooks/useAuthSettings.ts +14 -2
- package/src/hooks/usePublicAuthSettings.ts +38 -16
- package/src/lib/client-key.ts +88 -0
- package/src/lib/demo-mode.ts +2 -1
- package/src/lib/ensure-fresh-access-token.ts +12 -1
- package/src/lib/idp-client-config.ts +399 -36
- package/src/lib/idp-fetch.ts +36 -1
- package/src/lib/idp-url-guard.ts +37 -0
- package/src/lib/redis.ts +84 -6
- package/src/lib/session-cookie-shape.ts +184 -0
- package/src/lib/session-store.ts +152 -6
- package/src/lib/single-flight.ts +64 -0
- package/src/lib/token-lifecycle.ts +12 -0
- package/src/middleware/create-middleware.ts +11 -0
- package/src/models/SessionModel.ts +49 -0
- package/src/pages/admin-login/page.tsx +17 -127
- package/src/pages/security/EnhancedSecurityPage.tsx +95 -9
- package/src/pages/security/index.ts +3 -0
- package/src/pages/test-env/EmergencyLogoutPage.tsx +17 -5
- package/src/pages/test-env/JwtInspectPage.tsx +235 -20
- package/src/pages/test-env/RefreshTokenPage.tsx +22 -6
- package/src/pages/test-env/TestEnvPage.tsx +16 -4
- package/src/pages/test-env/guarded.tsx +81 -0
- package/src/pages/test-env/index.ts +59 -7
- package/src/routes/auth/logout.ts +4 -3
- package/src/routes/auth/passkey-signin.ts +13 -13
- package/src/routes/auth/refresh.ts +30 -1
- package/src/routes/auth/session.ts +98 -9
- package/src/routes/auth/settings.ts +144 -42
- package/src/routes/auth/viability.ts +129 -11
- package/src/routes/mfa/backup-code-verify.ts +1 -1
- package/src/routes/mfa/backup-codes.ts +10 -10
- package/src/routes/mfa/methods.ts +22 -22
- package/src/routes/mfa/totp-confirm.ts +10 -10
- package/src/routes/mfa/totp-enroll.ts +10 -10
- package/src/routes/mfa/totp-verify.ts +14 -14
- package/src/routes/passkeys/list.ts +10 -10
- package/src/routes/passkeys/manage.ts +23 -23
- package/src/routes/passkeys/register-options.ts +10 -10
- package/src/routes/passkeys/register-verify.ts +10 -10
- package/src/server/auth-guard.ts +24 -17
- package/src/server/auth.ts +54 -74
- package/src/server/decode-session.ts +95 -11
- package/src/templates/instrumentation.ts +21 -2
- package/src/types/auth.ts +20 -0
- package/dist/lib/auth-secret.d.ts +0 -17
- package/dist/lib/auth-secret.js +0 -116
- package/src/lib/auth-secret.ts +0 -137
|
@@ -5,30 +5,125 @@ const server_1 = require("next/server");
|
|
|
5
5
|
const auth_1 = require("../../server/auth");
|
|
6
6
|
const session_store_1 = require("../../lib/session-store");
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* ⚠️ DESTRUCTIVE TEST-ONLY HANDLER — DO NOT MOUNT IN PRODUCTION. ⚠️
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* which will trigger a refresh on the next
|
|
10
|
+
* Force-expire access token for testing refresh flow. Sets the access token
|
|
11
|
+
* expiry to 2 minutes in the past, which will trigger a refresh on the next
|
|
12
|
+
* API call.
|
|
13
|
+
*
|
|
14
|
+
* THIS MUTATES SESSION STATE. It is a test affordance, not a product feature.
|
|
15
|
+
*
|
|
16
|
+
* ── WHY THIS WARNING EXISTS (QAPert 34983) ────────────────────────────────
|
|
17
|
+
* The usage block below is not decoration: THIS DOCSTRING IS THE SPREAD
|
|
18
|
+
* MECHANISM. It ships compiled into dist and into the .d.ts, so it reaches
|
|
19
|
+
* every consumer's editor as hover text, and it is a one-line copy-paste that
|
|
20
|
+
* mounts a destructive endpoint. Every one of the three surfaces this route
|
|
21
|
+
* ended up on followed exactly these instructions.
|
|
22
|
+
*
|
|
23
|
+
* The handler itself was fixed (244877: default-deny behind ENABLE_TEST_ROUTES,
|
|
24
|
+
* plus the caller-supplied-token IDOR removed). But a fixed handler shipped
|
|
25
|
+
* with unqualified mounting instructions still spreads: the guidance was never
|
|
26
|
+
* corrected alongside the code, and a package that documents a dangerous route
|
|
27
|
+
* as a plain convenience is instructing the weaker configuration.
|
|
28
|
+
*
|
|
29
|
+
* ── IF YOU MOUNT IT, MOUNT IT LIKE THIS ───────────────────────────────────
|
|
30
|
+
* Required: set ENABLE_TEST_ROUTES=true IN THAT ENVIRONMENT ONLY. Absent, empty
|
|
31
|
+
* or any other value default-DENIES (404). Never set it in production.
|
|
12
32
|
*
|
|
13
|
-
* Usage in consuming app:
|
|
14
33
|
* ```typescript
|
|
15
|
-
* // app/api/test/force-expire/route.ts
|
|
34
|
+
* // app/api/test/force-expire/route.ts — TEST/DEV ENVIRONMENTS ONLY
|
|
35
|
+
* // Requires ENABLE_TEST_ROUTES=true in that environment; 404s otherwise.
|
|
16
36
|
* export { POST } from '@payez/next-mvp/api-handlers/test/force-expire';
|
|
17
37
|
* ```
|
|
38
|
+
*
|
|
39
|
+
* If you do not need to exercise the refresh flow, DO NOT MOUNT THIS AT ALL.
|
|
40
|
+
* The safest configuration is the absence of the route.
|
|
18
41
|
*/
|
|
19
42
|
const POST = async (req) => {
|
|
43
|
+
// 244877 (package-level): DEFAULT DENY behind ENABLE_TEST_ROUTES.
|
|
44
|
+
//
|
|
45
|
+
// This handler MUTATES session state — it rewrites idpAccessTokenExpires two
|
|
46
|
+
// minutes into the past — and was gated on nothing but "any signed-in
|
|
47
|
+
// session": no role check, no env kill-switch. Because consuming apps mount
|
|
48
|
+
// it with a one-line re-export, EVERY consumer inherited that, including
|
|
49
|
+
// deployments on production hosts.
|
|
50
|
+
//
|
|
51
|
+
// The card was raised against one app's local copy. Sweeping the pattern
|
|
52
|
+
// rather than the instance found the same route in three places — a local
|
|
53
|
+
// copy in the graft, a local copy in idealvibe.online, and idealresume.online
|
|
54
|
+
// re-exporting THIS handler — so the fix belongs here, at the source all
|
|
55
|
+
// three ultimately derive from, not only in whichever copy was noticed first.
|
|
56
|
+
//
|
|
57
|
+
// The gate is the FIRST statement, before any session decode, so a disabled
|
|
58
|
+
// build does not reveal that the route is live. Absent, empty, or any value
|
|
59
|
+
// other than 'true' disables it. Distinguishable body on purpose: a bare 404
|
|
60
|
+
// reads as "route missing / build broken" and sends someone debugging
|
|
61
|
+
// deployment instead of reading a flag.
|
|
62
|
+
//
|
|
63
|
+
// A consumer that genuinely needs this in a test environment sets
|
|
64
|
+
// ENABLE_TEST_ROUTES=true there, which is the same posture the token
|
|
65
|
+
// inspector already uses for a strictly LESS dangerous, read-only route.
|
|
66
|
+
if (process.env.ENABLE_TEST_ROUTES !== 'true') {
|
|
67
|
+
// DISCLOSURE IS CONDITIONAL ON ENVIRONMENT (QAPert-NightHawk 34539, after
|
|
68
|
+
// QAPert caught that my first version shipped the very leak we had just
|
|
69
|
+
// criticised elsewhere).
|
|
70
|
+
//
|
|
71
|
+
// My original body named the flag: "Set ENABLE_TEST_ROUTES=true...". That
|
|
72
|
+
// is the same class of disclosure as TOKEN_INSPECTOR_DISABLED — it confirms
|
|
73
|
+
// the route exists, names the capability, and hands a prober the exact
|
|
74
|
+
// switch that turns it on. Having argued against that pattern one directory
|
|
75
|
+
// over, shipping it here would have been incoherent.
|
|
76
|
+
//
|
|
77
|
+
// Deleting the message outright is also wrong: it is what stops a developer
|
|
78
|
+
// losing an hour deciding whether their build is broken. The tension
|
|
79
|
+
// resolves by AUDIENCE, not by picking a side:
|
|
80
|
+
// production -> 404, EMPTY body. Nothing about the capability, the
|
|
81
|
+
// flag, or even that a handler is here.
|
|
82
|
+
// non-production -> 404 + the helpful message naming the flag.
|
|
83
|
+
//
|
|
84
|
+
// The operator affordance survives in production too, via the log line
|
|
85
|
+
// below: logs are visible to operators and not to probers, which is exactly
|
|
86
|
+
// the split the response body cannot make.
|
|
87
|
+
console.warn('[FORCE-EXPIRE] blocked: ENABLE_TEST_ROUTES is not "true" (test routes default-deny).');
|
|
88
|
+
if (process.env.NODE_ENV === 'production') {
|
|
89
|
+
return new server_1.NextResponse(null, { status: 404 });
|
|
90
|
+
}
|
|
91
|
+
return server_1.NextResponse.json({
|
|
92
|
+
error: 'TEST_ROUTES_DISABLED',
|
|
93
|
+
message: 'Test routes are disabled in this build. Set ENABLE_TEST_ROUTES=true to enable them (development only).',
|
|
94
|
+
}, { status: 404 });
|
|
95
|
+
}
|
|
20
96
|
try {
|
|
21
97
|
const betterAuthSession = await (0, auth_1.getSession)(req);
|
|
22
|
-
|
|
98
|
+
// ACCESS CONTROL (QAPert 34553). This handler previously fell back to a
|
|
99
|
+
// CALLER-SUPPLIED `X-Session-Token` header when the request carried no
|
|
100
|
+
// session of its own, and then force-expired whatever token that header
|
|
101
|
+
// named — with NO check that the token belonged to the caller. The 401
|
|
102
|
+
// fired only when a caller supplied NEITHER a session NOR the header. So
|
|
103
|
+
// an UNAUTHENTICATED caller who presented any valid session token could
|
|
104
|
+
// expire ANOTHER USER'S session: an unauthenticated cross-session write.
|
|
105
|
+
//
|
|
106
|
+
// The fallback is removed rather than ownership-checked, because an
|
|
107
|
+
// ownership check would make it exactly equivalent to reading the caller's
|
|
108
|
+
// own session — the header could then never name anything else, so it
|
|
109
|
+
// would be a parameter that cannot legally vary. The session to expire is
|
|
110
|
+
// now ALWAYS the caller's own, which is also what the graft's local copy
|
|
111
|
+
// has always done.
|
|
112
|
+
//
|
|
113
|
+
// This is defence in depth, not the only control: the ENABLE_TEST_ROUTES
|
|
114
|
+
// gate above already 404s this handler by default. But the gate is
|
|
115
|
+
// switched ON in test environments, and "unauthenticated users can expire
|
|
116
|
+
// each other's sessions" is not acceptable there either — a control that
|
|
117
|
+
// only holds while a feature is switched off is not an access control.
|
|
118
|
+
//
|
|
119
|
+
// Corrects NextPert's own scope claim on card 244877 ("a caller could only
|
|
120
|
+
// ever expire their OWN session"): that was read off the graft's LOCAL
|
|
121
|
+
// copy, which derives the token from the caller's JWT. It was never true
|
|
122
|
+
// of THIS handler, which is the one consumers actually mount.
|
|
123
|
+
const sessionToken = betterAuthSession?.session?.token;
|
|
23
124
|
if (!sessionToken) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
sessionToken = headerSessionToken;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
console.warn('[TEST_EXPIRE] No session token or X-Session-Token header');
|
|
30
|
-
return server_1.NextResponse.json({ success: false, error: 'No session token' }, { status: 401 });
|
|
31
|
-
}
|
|
125
|
+
console.warn('[TEST_EXPIRE] No session on the request');
|
|
126
|
+
return server_1.NextResponse.json({ success: false, error: 'No session token' }, { status: 401 });
|
|
32
127
|
}
|
|
33
128
|
const session = await (0, session_store_1.getSession)(sessionToken);
|
|
34
129
|
if (!session) {
|
|
@@ -12,6 +12,12 @@ import 'server-only';
|
|
|
12
12
|
import { betterAuth } from 'better-auth';
|
|
13
13
|
import { type MagicLinkOptions } from 'better-auth/plugins/magic-link';
|
|
14
14
|
import type { IDPClientConfig } from '../lib/idp-client-config';
|
|
15
|
+
/**
|
|
16
|
+
* 185121: short sha256 fingerprint for secrets/tokens in log lines — enough
|
|
17
|
+
* to tell "same" from "divergent", never enough to reconstruct. 12 hex chars
|
|
18
|
+
* = 48 bits; collision-tellable across a deployment, useless as a credential.
|
|
19
|
+
*/
|
|
20
|
+
export declare function secretFingerprint(value: string): string;
|
|
15
21
|
/**
|
|
16
22
|
* Better Auth social provider config shape.
|
|
17
23
|
*/
|
|
@@ -22,7 +28,52 @@ export interface BetterAuthSocialProvider {
|
|
|
22
28
|
prompt?: string;
|
|
23
29
|
accessType?: 'offline' | 'online';
|
|
24
30
|
hd?: string;
|
|
31
|
+
/**
|
|
32
|
+
* 260419: better-auth's ONLY guard against OAuth auto-provisioning
|
|
33
|
+
* (oauth2/link-account.mjs handleOAuthUserInfo: `if (disableSignUp) return
|
|
34
|
+
* {error:"signup disabled"}`). Unset means ANY unknown Google identity gets a
|
|
35
|
+
* local account created at callback. We wire it from the tenant's own policy.
|
|
36
|
+
*/
|
|
37
|
+
disableSignUp?: boolean;
|
|
25
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* EXCHANGE-MOVE (175047): route OAuth through OUR IDP instead of holding
|
|
41
|
+
* provider credentials in the app.
|
|
42
|
+
*
|
|
43
|
+
* ARCHITECTURE LOCKED (BAPert 21318): genericOAuth pointed at the IDP - NOT at
|
|
44
|
+
* Google - which is simultaneously pkce + no-secret AND route-through-IDP, and
|
|
45
|
+
* is uniform with the ratified desktop leg. The IDP holds the provider secret
|
|
46
|
+
* and performs the provider exchange server-side.
|
|
47
|
+
*
|
|
48
|
+
* ── CUSTOM SHAPE, NEVER A PROVIDER PRESET ───────────────────────────────────
|
|
49
|
+
* QAPert-NightHawk 21304: better-auth's provider-PRESET shape makes
|
|
50
|
+
* clientSecret REQUIRED again. Same plugin, two config shapes, opposite answers
|
|
51
|
+
* on whether we need a secret. This builds the generic/custom shape
|
|
52
|
+
* deliberately; reaching for a preset because it looks tidier would silently
|
|
53
|
+
* kill keyless-on-web and nobody would connect the two changes.
|
|
54
|
+
*
|
|
55
|
+
* ── OPT-IN, AND NOT A FALLBACK ──────────────────────────────────────────────
|
|
56
|
+
* Returns null unless the IDP's OAuth endpoints are explicitly configured. That
|
|
57
|
+
* makes this ADDITIVE: the existing socialProviders path keeps working until an
|
|
58
|
+
* operator turns this on. It is NOT a runtime failover - nothing silently
|
|
59
|
+
* chooses between them, because a silent chooser is how a migration ends up
|
|
60
|
+
* half-applied and undetectable.
|
|
61
|
+
*
|
|
62
|
+
* ⚠ WHAT MUST MOVE TO THE IDP WITH THIS (flagged in 21317, not solvable here):
|
|
63
|
+
* the app stops talking to Google, so it can no longer capture the raw
|
|
64
|
+
* id_token that oauth-callback verifies today, and the per-provider settings
|
|
65
|
+
* below stop being ours to set - profile scope, prompt=select_account,
|
|
66
|
+
* accessType, and hd (hosted-domain, a SECURITY control). The IDP's own
|
|
67
|
+
* exchange must verify signature/iss/aud/exp itself and preserve those four, or
|
|
68
|
+
* they are lost silently.
|
|
69
|
+
*/
|
|
70
|
+
export declare function buildIdpOAuthProviderConfig(): {
|
|
71
|
+
providerId: string;
|
|
72
|
+
discoveryUrl: string;
|
|
73
|
+
clientId: string;
|
|
74
|
+
pkce: true;
|
|
75
|
+
scopes: string[];
|
|
76
|
+
} | null;
|
|
26
77
|
export declare function buildBetterAuthProviders(config: IDPClientConfig): Record<string, BetterAuthSocialProvider>;
|
|
27
78
|
/**
|
|
28
79
|
* Optional configuration for `createBetterAuthInstance`.
|
|
@@ -69,7 +120,58 @@ export declare function createBetterAuthInstance(idpConfig: IDPClientConfig, opt
|
|
|
69
120
|
socialProviders: Record<string, BetterAuthSocialProvider>;
|
|
70
121
|
trustedOrigins: string[];
|
|
71
122
|
secondaryStorage: {
|
|
123
|
+
/**
|
|
124
|
+
* 170033 (QAPert 22654, load-bearing precondition for 183483): DO NOT
|
|
125
|
+
* swallow a Redis failure into `null` here.
|
|
126
|
+
*
|
|
127
|
+
* `null` from `get` is Better Auth's OWN signal for "no session at this
|
|
128
|
+
* key" (see node_modules/better-auth db/internal-adapter.mjs
|
|
129
|
+
* `findSession`: `if (!sessionStringified ...) return null`). Catching
|
|
130
|
+
* a Redis error and returning `null` therefore told better-auth "this
|
|
131
|
+
* session does not exist" when the true state was "the store could not
|
|
132
|
+
* be asked" — indistinguishable from a genuine sign-out. With
|
|
133
|
+
* `cookieCache` disabled (session.cookieCache.enabled above), EVERY
|
|
134
|
+
* `getSession()` call hits this path for real, so a Redis blip
|
|
135
|
+
* manufactured a `200 { session: null }` for every live session at
|
|
136
|
+
* once — the exact channel 183483's client-side guard (verify-code
|
|
137
|
+
* page's session-liveness check) was built to survive, and the one it
|
|
138
|
+
* could not survive while this swallow stood: a fabricated "no
|
|
139
|
+
* session" 200 is not distinguishable from a real one by any client.
|
|
140
|
+
*
|
|
141
|
+
* Letting the error propagate is safe: better-auth's own router
|
|
142
|
+
* (better-call/dist/router.mjs) wraps every endpoint handler in a
|
|
143
|
+
* top-level try/catch and converts an uncaught throw to a genuine
|
|
144
|
+
* `500`, not a crash. A `500` IS the "inconclusive" signal 183483's
|
|
145
|
+
* corrected client guard already knows how to hold a session through —
|
|
146
|
+
* so a Redis outage now surfaces as "couldn't check" instead of
|
|
147
|
+
* silently lying "confirmed logged out".
|
|
148
|
+
*/
|
|
72
149
|
get: (key: string) => Promise<string | null>;
|
|
150
|
+
/**
|
|
151
|
+
* 170033 fix 1 — DO NOT SWALLOW A FAILED WRITE. A SESSION THAT WAS NOT
|
|
152
|
+
* PERSISTED IS NOT A SESSION.
|
|
153
|
+
*
|
|
154
|
+
* This previously caught every Redis error and returned normally, so
|
|
155
|
+
* better-auth was told the session had been stored when nothing had been
|
|
156
|
+
* written. The user got a successful login, a session cookie, and a
|
|
157
|
+
* rendered signed-in shell on top of a store that holds no session — and
|
|
158
|
+
* the very next `getSession()` reads `null` and signs them straight back
|
|
159
|
+
* out. Nothing logged, nothing thrown, no banner: a login that "worked"
|
|
160
|
+
* and a sign-out nobody can explain.
|
|
161
|
+
*
|
|
162
|
+
* Letting it propagate is the same contract `get` above already relies on:
|
|
163
|
+
* better-auth's router (better-call/dist/router.mjs) wraps every endpoint
|
|
164
|
+
* handler and converts an uncaught throw into a genuine 500. A 500 on the
|
|
165
|
+
* login write is honest — "we could not store your session" — and it is
|
|
166
|
+
* distinguishable by any client from a successful login, which a swallowed
|
|
167
|
+
* failure is not.
|
|
168
|
+
*
|
|
169
|
+
* THE COMMENT THIS REPLACES SAID "Redis unavailable — cookie cache still
|
|
170
|
+
* works". It does not: `session.cookieCache.enabled` is FALSE (see below).
|
|
171
|
+
* The comment described a safety net that had been removed, which is why
|
|
172
|
+
* this swallow looked survivable to every reader who trusted it (170033
|
|
173
|
+
* fix 3).
|
|
174
|
+
*/
|
|
73
175
|
set: (key: string, value: string, ttl?: number) => Promise<void>;
|
|
74
176
|
delete: (key: string) => Promise<void>;
|
|
75
177
|
};
|
|
@@ -195,18 +297,173 @@ export declare function createBetterAuthInstance(idpConfig: IDPClientConfig, opt
|
|
|
195
297
|
max: number;
|
|
196
298
|
}[];
|
|
197
299
|
options: MagicLinkOptions;
|
|
300
|
+
} | {
|
|
301
|
+
id: "generic-oauth";
|
|
302
|
+
init: (ctx: import("better-auth").AuthContext) => {
|
|
303
|
+
context: {
|
|
304
|
+
socialProviders: import("better-auth").OAuthProvider<Record<string, any>, Partial<import("better-auth").ProviderOptions<any>>>[];
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
endpoints: {
|
|
308
|
+
signInWithOAuth2: import("better-auth").StrictEndpoint<"/sign-in/oauth2", {
|
|
309
|
+
method: "POST";
|
|
310
|
+
body: import("better-auth").ZodObject<{
|
|
311
|
+
providerId: import("better-auth").ZodString;
|
|
312
|
+
callbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
313
|
+
errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
314
|
+
newUserCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
315
|
+
disableRedirect: import("better-auth").ZodOptional<import("better-auth").ZodBoolean>;
|
|
316
|
+
scopes: import("better-auth").ZodOptional<import("better-auth").ZodArray<import("better-auth").ZodString>>;
|
|
317
|
+
requestSignUp: import("better-auth").ZodOptional<import("better-auth").ZodBoolean>;
|
|
318
|
+
additionalData: import("better-auth").ZodOptional<import("better-auth").ZodRecord<import("better-auth").ZodString, import("better-auth").ZodAny>>;
|
|
319
|
+
}, import("better-auth").$strip>;
|
|
320
|
+
metadata: {
|
|
321
|
+
openapi: {
|
|
322
|
+
description: string;
|
|
323
|
+
responses: {
|
|
324
|
+
200: {
|
|
325
|
+
description: string;
|
|
326
|
+
content: {
|
|
327
|
+
"application/json": {
|
|
328
|
+
schema: {
|
|
329
|
+
type: "object";
|
|
330
|
+
properties: {
|
|
331
|
+
url: {
|
|
332
|
+
type: string;
|
|
333
|
+
};
|
|
334
|
+
redirect: {
|
|
335
|
+
type: string;
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
}, {
|
|
346
|
+
url: string;
|
|
347
|
+
redirect: boolean;
|
|
348
|
+
}>;
|
|
349
|
+
oAuth2Callback: import("better-auth").StrictEndpoint<"/oauth2/callback/:providerId", {
|
|
350
|
+
method: "GET";
|
|
351
|
+
query: import("better-auth").ZodObject<{
|
|
352
|
+
code: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
353
|
+
error: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
354
|
+
error_description: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
355
|
+
state: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
356
|
+
iss: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
357
|
+
}, import("better-auth").$strip>;
|
|
358
|
+
metadata: {
|
|
359
|
+
allowedMediaTypes: string[];
|
|
360
|
+
openapi: {
|
|
361
|
+
description: string;
|
|
362
|
+
responses: {
|
|
363
|
+
200: {
|
|
364
|
+
description: string;
|
|
365
|
+
content: {
|
|
366
|
+
"application/json": {
|
|
367
|
+
schema: {
|
|
368
|
+
type: "object";
|
|
369
|
+
properties: {
|
|
370
|
+
url: {
|
|
371
|
+
type: string;
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
scope: "server";
|
|
381
|
+
};
|
|
382
|
+
}, void>;
|
|
383
|
+
oAuth2LinkAccount: import("better-auth").StrictEndpoint<"/oauth2/link", {
|
|
384
|
+
method: "POST";
|
|
385
|
+
body: import("better-auth").ZodObject<{
|
|
386
|
+
providerId: import("better-auth").ZodString;
|
|
387
|
+
callbackURL: import("better-auth").ZodString;
|
|
388
|
+
scopes: import("better-auth").ZodOptional<import("better-auth").ZodArray<import("better-auth").ZodString>>;
|
|
389
|
+
errorCallbackURL: import("better-auth").ZodOptional<import("better-auth").ZodString>;
|
|
390
|
+
}, import("better-auth").$strip>;
|
|
391
|
+
use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
392
|
+
session: {
|
|
393
|
+
session: Record<string, any> & {
|
|
394
|
+
id: string;
|
|
395
|
+
createdAt: Date;
|
|
396
|
+
updatedAt: Date;
|
|
397
|
+
userId: string;
|
|
398
|
+
expiresAt: Date;
|
|
399
|
+
token: string;
|
|
400
|
+
ipAddress?: string | null | undefined;
|
|
401
|
+
userAgent?: string | null | undefined;
|
|
402
|
+
};
|
|
403
|
+
user: Record<string, any> & {
|
|
404
|
+
id: string;
|
|
405
|
+
createdAt: Date;
|
|
406
|
+
updatedAt: Date;
|
|
407
|
+
email: string;
|
|
408
|
+
emailVerified: boolean;
|
|
409
|
+
name: string;
|
|
410
|
+
image?: string | null | undefined;
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
}>)[];
|
|
414
|
+
metadata: {
|
|
415
|
+
openapi: {
|
|
416
|
+
description: string;
|
|
417
|
+
responses: {
|
|
418
|
+
"200": {
|
|
419
|
+
description: string;
|
|
420
|
+
content: {
|
|
421
|
+
"application/json": {
|
|
422
|
+
schema: {
|
|
423
|
+
type: "object";
|
|
424
|
+
properties: {
|
|
425
|
+
url: {
|
|
426
|
+
type: string;
|
|
427
|
+
format: string;
|
|
428
|
+
description: string;
|
|
429
|
+
};
|
|
430
|
+
redirect: {
|
|
431
|
+
type: string;
|
|
432
|
+
description: string;
|
|
433
|
+
enum: boolean[];
|
|
434
|
+
};
|
|
435
|
+
};
|
|
436
|
+
required: string[];
|
|
437
|
+
};
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
}, {
|
|
445
|
+
url: string;
|
|
446
|
+
redirect: boolean;
|
|
447
|
+
}>;
|
|
448
|
+
};
|
|
449
|
+
options: import("better-auth/plugins/generic-oauth").GenericOAuthOptions;
|
|
450
|
+
$ERROR_CODES: {
|
|
451
|
+
INVALID_OAUTH_CONFIGURATION: import("better-auth").RawError<"INVALID_OAUTH_CONFIGURATION">;
|
|
452
|
+
TOKEN_URL_NOT_FOUND: import("better-auth").RawError<"TOKEN_URL_NOT_FOUND">;
|
|
453
|
+
PROVIDER_CONFIG_NOT_FOUND: import("better-auth").RawError<"PROVIDER_CONFIG_NOT_FOUND">;
|
|
454
|
+
PROVIDER_ID_REQUIRED: import("better-auth").RawError<"PROVIDER_ID_REQUIRED">;
|
|
455
|
+
INVALID_OAUTH_CONFIG: import("better-auth").RawError<"INVALID_OAUTH_CONFIG">;
|
|
456
|
+
SESSION_REQUIRED: import("better-auth").RawError<"SESSION_REQUIRED">;
|
|
457
|
+
ISSUER_MISMATCH: import("better-auth").RawError<"ISSUER_MISMATCH">;
|
|
458
|
+
ISSUER_MISSING: import("better-auth").RawError<"ISSUER_MISSING">;
|
|
459
|
+
};
|
|
198
460
|
})[]];
|
|
199
461
|
}>;
|
|
200
462
|
/**
|
|
201
463
|
* Better Auth is always enabled (NextAuth removed in 4.0).
|
|
202
464
|
*/
|
|
203
465
|
export declare function isBetterAuthEnabled(): boolean;
|
|
204
|
-
|
|
205
|
-
* Get Better Auth Next.js route handlers (GET, POST).
|
|
206
|
-
* Initializes Better Auth from IDP config on first call, caches the instance.
|
|
207
|
-
*/
|
|
208
|
-
declare let cachedInstance: any;
|
|
209
|
-
export { cachedInstance as __betterAuthInstance };
|
|
466
|
+
export declare function __getBetterAuthInstance(): unknown;
|
|
210
467
|
/**
|
|
211
468
|
* Configure Better Auth instance options for this process.
|
|
212
469
|
*
|