@lpshanley/oidc-start-react 0.4.2 → 0.4.3

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/dist/context.d.ts CHANGED
@@ -12,6 +12,8 @@ export type OidcContext = {
12
12
  auth: () => OidcAuth;
13
13
  /** Queue a Set-Cookie line for the final response. */
14
14
  appendSetCookie: (line: string) => void;
15
+ /** Drop cookie writes from resolving the incoming session when a handler supersedes it. */
16
+ discardSessionUpdates?: () => void;
15
17
  };
16
18
  /** The current request's OIDC context; throws outside the middleware. */
17
19
  export declare function getOidcContext(): OidcContext;
@@ -29,7 +29,8 @@ export function oidcMiddleware(setup) {
29
29
  }
30
30
  const call = callContext(context);
31
31
  const { cookies, session, setCookies } = await core.resolve(request, call);
32
- const pending = [...setCookies];
32
+ let sessionUpdates = setCookies;
33
+ const appended = [];
33
34
  const oidc = {
34
35
  core,
35
36
  request,
@@ -37,9 +38,11 @@ export function oidcMiddleware(setup) {
37
38
  session,
38
39
  call,
39
40
  auth: () => ({ user: session?.user ?? null }),
40
- appendSetCookie: (line) => pending.push(line),
41
+ appendSetCookie: (line) => appended.push(line),
42
+ discardSessionUpdates: () => { sessionUpdates = []; },
41
43
  };
42
44
  const result = await next({ context: { oidc } });
45
+ const pending = [...sessionUpdates, ...appended];
43
46
  if (pending.length) {
44
47
  // Start must receive its original response to serialize RPC redirects.
45
48
  const { appendResponseHeader } = await import("@tanstack/react-start/server");
@@ -46,6 +46,8 @@ export async function signInRoute(request, options) {
46
46
  export async function callbackRoute(request, options) {
47
47
  const context = getOidcContext();
48
48
  const result = await context.core.callback(request, context.cookies, context.call);
49
+ if (result.ok)
50
+ context.discardSessionUpdates?.();
49
51
  for (const line of result.setCookies)
50
52
  context.appendSetCookie(line);
51
53
  if (result.ok)
@@ -1,6 +1,9 @@
1
1
  import { getOidcContext } from "./context.js";
2
2
  export async function endSession(everywhere = false) {
3
3
  const context = getOidcContext();
4
+ // A failed revocation must leave the incoming cookie available for retry.
5
+ // A successful sign-out supplies all deletions for that same incoming jar.
6
+ context.discardSessionUpdates?.();
4
7
  let result;
5
8
  try {
6
9
  result = await context.core.signOut(context.request, context.cookies, context.session, context.call, everywhere);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpshanley/oidc-start-react",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,7 +40,7 @@
40
40
  "node": ">=22.12.0"
41
41
  },
42
42
  "dependencies": {
43
- "@lpshanley/oidc-start-core": "0.4.2",
43
+ "@lpshanley/oidc-start-core": "0.4.3",
44
44
  "zod": "4.6.7"
45
45
  },
46
46
  "devDependencies": {