( target: TargetShape, identity: Identity, )
| 46 | |
| 47 | /** The identity's active org, with the name the dashboard shows. */ |
| 48 | const orgOf = ( |
| 49 | target: TargetShape, |
| 50 | identity: Identity, |
| 51 | ): Effect.Effect<{ readonly id: string; readonly slug: string; readonly name: string }> => |
| 52 | Effect.promise(async () => { |
| 53 | const response = await fetch(new URL("/api/auth/me", target.baseUrl), { |
| 54 | headers: { cookie: cookieOf(identity) }, |
| 55 | }); |
| 56 | if (!response.ok) throw new Error(`/api/auth/me failed (${response.status})`); |
| 57 | const body = (await response.json()) as { |
| 58 | organization: { id: string; slug: string; name: string } | null; |
| 59 | }; |
| 60 | if (!body.organization) throw new Error("identity has no active organization"); |
| 61 | return body.organization; |
| 62 | }); |
| 63 | |
| 64 | /** Write WorkOS organization metadata the way v2 does: Update Organization. */ |
| 65 | const setOrgMetadata = ( |
no test coverage detected