@oauth-spa-kit/server 2.0.3 → 2.0.5

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.
@@ -13,6 +13,18 @@ export interface OAuthHandlersConfig {
13
13
  refreshThresholdSeconds?: number;
14
14
  defaultReturnTo?: string;
15
15
  fetchImpl?: typeof fetch;
16
+ /**
17
+ * Called with the raw thrown error whenever the callback handler's token
18
+ * exchange or id_token verification fails, right before it's collapsed
19
+ * down to a short, URL-safe error code and redirected to
20
+ * `returnTo?login_error=...`. The full error (e.g. TokenExchangeError's
21
+ * `errorDescription`, or a JwtVerificationError's message) is never put in
22
+ * that URL -- it may embed the AS's free-text description -- so without
23
+ * this hook the only way to see *why* a login failed is to re-derive it
24
+ * from the AS's own server-side logs. Optional; defaults to a no-op, so
25
+ * existing consumers see no behavior change.
26
+ */
27
+ onCallbackError?: (error: unknown) => void;
16
28
  }
17
29
  export declare function createLoginHandler(config: OAuthHandlersConfig): (request: Request) => Promise<Response>;
18
30
  export declare function createCallbackHandler(config: OAuthHandlersConfig): (request: Request) => Promise<Response>;
package/dist/handlers.js CHANGED
@@ -135,6 +135,7 @@ export function createCallbackHandler(config) {
135
135
  return new Response(null, { status: 302, headers });
136
136
  }
137
137
  catch (cause) {
138
+ config.onCallbackError?.(cause);
138
139
  // Prefer the AS's own OAuth error code (e.g. "invalid_grant") over the
139
140
  // full exception message -- short, stable, safe to put in a URL query
140
141
  // param; the full message may embed the AS's free-text error_description.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oauth-spa-kit/server",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "BFF-pattern OAuth handlers: sealed HttpOnly-cookie sessions + login/callback/refresh/logout route factories, built on Web-standard Request/Response so they drop into Nitro, Next.js route handlers, Cloudflare Workers, or plain Node (via a small adapter).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,7 +22,7 @@
22
22
  "node": ">=18"
23
23
  },
24
24
  "dependencies": {
25
- "@oauth-spa-kit/core": "2.0.3"
25
+ "@oauth-spa-kit/core": "2.0.5"
26
26
  },
27
27
  "devDependencies": {
28
28
  "typescript": "^5.6.0",