( target: TargetShape, identity: Identity, )
| 170 | |
| 171 | /** The org this identity's session is currently bound to: id and URL slug. */ |
| 172 | export const activeOrg = ( |
| 173 | target: TargetShape, |
| 174 | identity: Identity, |
| 175 | ): Effect.Effect<{ readonly id: string; readonly slug: string }> => |
| 176 | Effect.promise(async () => { |
| 177 | const response = await fetch(new URL("/api/auth/me", target.baseUrl), { |
| 178 | headers: { cookie: cookieOf(identity) }, |
| 179 | }); |
| 180 | if (!response.ok) throw new Error(`/api/auth/me failed (${response.status})`); |
| 181 | const body = (await response.json()) as { |
| 182 | organization: { id: string; slug: string } | null; |
| 183 | }; |
| 184 | if (!body.organization) throw new Error("identity has no active organization"); |
| 185 | return { id: body.organization.id, slug: body.organization.slug }; |
| 186 | }); |
| 187 | |
| 188 | /** Every org this account is a member of, plus the one the session is on. */ |
| 189 | export const organizationsOf = ( |
no test coverage detected