@reflagged/shell 1.3.0 → 1.3.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/README.md CHANGED
@@ -46,9 +46,39 @@ import { loadAppConfig } from '@reflagged/shell/config'
46
46
  import { OIDC_COOKIE, loadOidcEnv } from '@reflagged/shell/auth/oidc-config'
47
47
  import { verifySessionCookie } from '@reflagged/shell/auth/oidc-cookie'
48
48
  import { refreshAccessToken } from '@reflagged/shell/auth/oidc-refresh'
49
- import { nextauthStrategy } from '@reflagged/shell/auth/nextauth-strategy'
49
+ import { nextauthStrategy, createOidcStrategy } from '@reflagged/shell/auth/nextauth-strategy'
50
50
  ```
51
51
 
52
+ ### Mapping the platform's role onto your own (`roleForNewUser`)
53
+
54
+ `nextauthStrategy` is `createOidcStrategy()` with no options — the role a
55
+ newly created account gets is `RFLGD_DEFAULT_USER_ROLE` (or `admin` for the
56
+ very first account). Call `createOidcStrategy` directly to decide that role
57
+ yourself from the platform's view of the person, using the workspace role
58
+ the platform put in the session:
59
+
60
+ ```ts
61
+ import { createOidcStrategy, type NewUserContext } from '@reflagged/shell/auth/nextauth-strategy'
62
+
63
+ function roleForNewUser({ orgRole, isFirstUser }: NewUserContext): string {
64
+ if (isFirstUser) return 'admin'
65
+ // org_role is three-valued, not two: 'owner' | 'admin' | 'member' when a
66
+ // membership row exists (both 'owner' and 'admin' administer the
67
+ // workspace), or a *platform* role — 'superadmin' | 'reflagged_admin' |
68
+ // 'tenant_admin' | 'member' — when it does not. Check for 'owner' as well
69
+ // as 'admin': the person who books an instance is always created as
70
+ // 'owner', never 'admin'.
71
+ return orgRole === 'owner' || orgRole === 'admin' ? 'workspace-admin' : 'member'
72
+ }
73
+
74
+ export const oidcStrategy = createOidcStrategy({ roleForNewUser })
75
+ ```
76
+
77
+ This callback runs only when an account is created, never on later
78
+ sign-ins — see `NewUserContext`'s doc comments in
79
+ `src/lib/auth/nextauth-strategy.ts` for the full contract, including the
80
+ `isFirstUser` branch and the `null` case for standalone operation.
81
+
52
82
  ### Per-app route files + middleware
53
83
 
54
84
  Each app keeps thin wrappers that re-export the handlers:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reflagged/shell",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Shared app shell for Reflagged services — OIDC auth, SSO, app switcher",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -7,7 +7,18 @@ import { verifySessionCookie } from './oidc-cookie'
7
7
 
8
8
  /** What the platform knows about a person signing in for the first time. */
9
9
  export type NewUserContext = {
10
- /** Role in the current workspace ('admin' | 'member'), null without claims. */
10
+ /**
11
+ * Role in the current workspace, when a membership row exists for it:
12
+ * 'owner' | 'admin' | 'member'. When no membership row exists, the
13
+ * platform substitutes a *platform* role instead — 'superadmin' |
14
+ * 'reflagged_admin' | 'tenant_admin' | 'member' — a second, unrelated
15
+ * vocabulary in the same field (rflgd-base `src/lib/oidc/provider.ts:163`,
16
+ * `org_role: orgRole ?? userRole ?? null`). Only `null` without any claims
17
+ * at all. Callers that special-case 'admin' should check 'owner' too —
18
+ * rflgd-base always creates the booking person's membership with
19
+ * 'owner', never 'admin' (`src/lib/access/service-access.ts:20` treats
20
+ * both as equally privileged).
21
+ */
11
22
  orgRole: string | null
12
23
  /** Role on the platform itself, null without claims. */
13
24
  platformRole: string | null