@lpshanley/oidc-start-react 0.5.0 → 0.7.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/README.md CHANGED
@@ -51,6 +51,8 @@ export const startInstance = createStart(() => ({
51
51
  }))
52
52
  ```
53
53
 
54
+ `oidcMiddleware` serves one core. The `core` function takes no arguments and runs once, on the first request; its result is reused for every request after. It cannot pick a configuration per request.
55
+
54
56
  ## 3. Add the callback route
55
57
 
56
58
  Create `src/routes/callback.ts`. The handler checks the provider response, establishes the session, and redirects to the local path chosen at sign-in.
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type ReactElement, type ReactNode } from "react";
2
- import { type AuthSession, type SignInOptions, type SignOutOptions } from "@lpshanley/oidc-start-core/models";
2
+ import type { AuthSession, SignInOptions, SignOutOptions } from "@lpshanley/oidc-start-core/models";
3
3
  /** Supply the root loader's getAuth() result for SSR and client navigation. */
4
4
  export declare function AuthProvider({ auth, children }: {
5
5
  auth: AuthSession;
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createContext, createElement, Fragment, useContext } from "react";
2
2
  import { useServerFn } from "@tanstack/react-start";
3
- import { hasRole } from "@lpshanley/oidc-start-core/models";
3
+ import { hasRole } from "@lpshanley/oidc-start-core/helpers";
4
4
  import { getSignInUrl, signOut } from "./functions.js";
5
5
  const AuthContext = createContext(undefined);
6
6
  /** Supply the root loader's getAuth() result for SSR and client navigation. */
@@ -40,7 +40,10 @@ export declare function requireRecentAuth(options: GuardOptions & {
40
40
  roles?: string[] | undefined;
41
41
  };
42
42
  }>;
43
- /** An authorization URL; also queues the flow's verifier cookie. */
43
+ /**
44
+ * An authorization URL; also starts a flow and queues its verifier cookie.
45
+ * That is a state change, so it is a POST and the CSRF middleware covers it.
46
+ */
44
47
  export declare const getSignInUrl: import("@tanstack/react-start").OptionalFetcher<undefined, z.ZodOptional<z.ZodObject<{
45
48
  returnPathname: z.ZodOptional<z.ZodString>;
46
49
  maxAge: z.ZodOptional<z.ZodNumber>;
package/dist/functions.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { createServerFn } from "@tanstack/react-start";
2
2
  import { redirect } from "@tanstack/react-router";
3
3
  import { z } from "zod";
4
- import { sanitizeReturnPath, signInOptionsSchema, signOutOptionsSchema } from "@lpshanley/oidc-start-core/models";
4
+ import { sanitizeReturnPath } from "@lpshanley/oidc-start-core/helpers";
5
+ import { signInOptionsSchema, signOutOptionsSchema } from "@lpshanley/oidc-start-core/models";
5
6
  // Server functions after WorkOS's server-functions.ts; bodies load lazily so
6
7
  // server code stays out of the client bundle.
7
8
  /** The signed-in user, or null. Never returns tokens. */
@@ -36,8 +37,11 @@ export async function requireRecentAuth(options) {
36
37
  redirectToSignIn(options, options.maxAge);
37
38
  return { user };
38
39
  }
39
- /** An authorization URL; also queues the flow's verifier cookie. */
40
- export const getSignInUrl = createServerFn({ method: "GET" })
40
+ /**
41
+ * An authorization URL; also starts a flow and queues its verifier cookie.
42
+ * That is a state change, so it is a POST and the CSRF middleware covers it.
43
+ */
44
+ export const getSignInUrl = createServerFn({ method: "POST" })
41
45
  .validator(signInOptionsSchema.optional())
42
46
  .handler(async ({ data }) => {
43
47
  const { getSignInUrlBody } = await import("./functions.server.js");
@@ -20,6 +20,7 @@ export function getRecentAuthBody(maxAge) {
20
20
  return checkRecentAuth({ maxAge }).isStale ? { user: null } : auth;
21
21
  }
22
22
  export async function getSignInUrlBody(options) {
23
+ setResponseHeader("Cache-Control", "no-store");
23
24
  const context = getOidcContext();
24
25
  const { url, setCookies } = await context.core.signIn(context.request, context.cookies, options, context.call);
25
26
  for (const line of setCookies)
@@ -3,10 +3,12 @@ import type { OidcContext } from "./context.js";
3
3
  import type { OidcCore } from "@lpshanley/oidc-start-core";
4
4
  export type OidcMiddlewareSetup = OidcMiddlewareOptions | {
5
5
  /**
6
- * A core the app composed itself, resolved on first request from
7
- * the context earlier request middleware provided.
6
+ * A core the app composed itself. One middleware serves one core:
7
+ * this is called once, on the first request, and the result is
8
+ * reused for every request after. It cannot choose a core per
9
+ * request. For several tenants, create one middleware per tenant.
8
10
  */
9
- core: (context: unknown) => OidcCore;
11
+ core: () => OidcCore;
10
12
  };
11
13
  /**
12
14
  * Request middleware after WorkOS's authkitMiddleware: resolves the session
@@ -22,7 +22,7 @@ export function oidcMiddleware(setup) {
22
22
  let core;
23
23
  return createMiddleware({ type: "request" }).server(async ({ request, next, context }) => {
24
24
  if ("core" in setup)
25
- core ??= setup.core(context);
25
+ core ??= setup.core();
26
26
  else {
27
27
  const { createOidcCore } = await import("@lpshanley/oidc-start-core");
28
28
  core ??= createOidcCore(setup);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpshanley/oidc-start-react",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
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.5.0",
43
+ "@lpshanley/oidc-start-core": "0.7.0",
44
44
  "zod": "4.6.7"
45
45
  },
46
46
  "devDependencies": {