@spawn-llc/auth 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.1
4
+
5
+ **Fix: the session readers now force dynamic rendering before any early return.**
6
+
7
+ `currentUser()`, `session()` and `rejectedEmail()` returned `null` when WorkOS was unconfigured
8
+ *before* touching `headers()`. Every build runs without `WORKOS_*` env, so that short-circuit told
9
+ Next the page was static — baking a signed-out verdict into HTML, and failing the build outright on
10
+ any page that queries a database while prerendering. Found while migrating `admin`, whose own
11
+ pre-migration code touched `headers()` first for exactly this reason.
12
+
3
13
  ## 0.2.0
4
14
 
5
15
  **Security — read this before upgrading an internal tool.**
@@ -1,11 +1,6 @@
1
1
  import { U as User, S as Session } from '../domain-CmEhGW2N.js';
2
2
  import * as next_server from 'next/server';
3
3
 
4
- /**
5
- * The Spawn session seam for Next apps. ONE choke point: app code only ever calls `currentUser()` /
6
- * `requireUser()` / `session()` / `signOut()` — nothing outside this package knows it's WorkOS.
7
- * Generalized from admin's `@admin/auth` + audit's `lib/session.ts`.
8
- */
9
4
  /** The signed-in Spawn user, or null. Applies the optional email-domain gate. */
10
5
  declare function currentUser(): Promise<User | null>;
11
6
  /** The signed-in user; redirects to `/login` when absent. */
@@ -1,9 +1,13 @@
1
1
  import { isWorkosConfigured, isAllowedEmail, publicPaths, workosClientId } from '../chunk-ZIYU4K3F.js';
2
+ import { headers, cookies } from 'next/headers';
2
3
  import { redirect } from 'next/navigation';
3
4
  import { authkitMiddleware, handleAuth, getWorkOS, saveSession } from '@workos-inc/authkit-nextjs';
4
- import { headers, cookies } from 'next/headers';
5
5
 
6
+ async function markDynamic() {
7
+ await headers();
8
+ }
6
9
  async function currentUser() {
10
+ await markDynamic();
7
11
  if (!isWorkosConfigured()) return null;
8
12
  const { withAuth } = await import('@workos-inc/authkit-nextjs');
9
13
  const { user } = await withAuth();
@@ -16,6 +20,7 @@ async function requireUser(redirectTo = "/login") {
16
20
  return user;
17
21
  }
18
22
  async function session() {
23
+ await markDynamic();
19
24
  if (!isWorkosConfigured()) return null;
20
25
  const { withAuth } = await import('@workos-inc/authkit-nextjs');
21
26
  const info = await withAuth();
@@ -27,6 +32,7 @@ async function session() {
27
32
  };
28
33
  }
29
34
  async function rejectedEmail() {
35
+ await markDynamic();
30
36
  if (!isWorkosConfigured()) return null;
31
37
  const { withAuth } = await import('@workos-inc/authkit-nextjs');
32
38
  const { user } = await withAuth();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spawn-llc/auth",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Spawn shared identity — headless auth for the whole Spawn suite. One WorkOS project (named \"Spawn\") backs every app; this is the only place that touches it. WorkOS is an invisible engine.",
5
5
  "license": "MIT",
6
6
  "type": "module",