The console URL's org slug is now the request scope on the client too: both API clients (core + account) read the slug from window.location at request time and send it as the x-executor-organization header, so every tab's requests are scoped to the org its own URL names — independent of the single shared session cookie. With requests URL-scoped, the cookie-based switch machinery is dead weight: - delete the switchOrganization endpoint/handler/atom; the org switcher and create-org just navigate to /<slug> (the session already authenticates the user to all their orgs, so there is nothing to switch server-side). - delete ForeignOrgSlug; a slug the caller can't access now resolves to a null org via /account/me and the shell 404s, no switch-into-org dance. - simplify OrgSlugGate to canonicalize a bare URL onto the active slug and otherwise render through (a slug in the URL is already the scope). Flips the multi-tab scenario from reproducing the cookie-steal corruption to asserting per-tab independence, and reframes the foreign-slug scenario around URL scoping (no session switch; the cookie is never rewritten).
Showing the changes to apps/cloud/src/auth (2 of 14 files). Show all
Unified · Split
| @@ -34,10 +34,6 @@ const AuthOrganizationsResponse = Schema.Struct({ · 33 unmodified lines | |||
| 34 | activeOrganizationId: Schema.NullOr(Schema.String), | 34 | activeOrganizationId: Schema.NullOr(Schema.String), |
| 35 | }); | 35 | }); |
| 36 | 36 | ||
| 37 | const SwitchOrganizationBody = Schema.Struct({ | ||
| 38 | organizationId: Schema.String, | ||
| 39 | }); | ||
| 40 | |||
| 41 | const CreateOrganizationBody = Schema.Struct({ | 37 | const CreateOrganizationBody = Schema.Struct({ |
| 42 | name: Schema.String, | 38 | name: Schema.String, |
| 43 | }); | 39 | }); |
| @@ -143,7 +139,6 @@ export const AUTH_PATHS = { · 99 unmodified lines | |||
| 143 | login: "/api/auth/login", | 139 | login: "/api/auth/login", |
| 144 | logout: "/api/auth/logout", | 140 | logout: "/api/auth/logout", |
| 145 | callback: "/api/auth/callback", | 141 | callback: "/api/auth/callback", |
| 146 | switchOrganization: "/api/auth/switch-organization", | ||
| 147 | } as const; | 142 | } as const; |
| 148 | 143 | ||
| 149 | const AuthErrors = [UserStoreError, WorkOSError] as const; | 144 | const AuthErrors = [UserStoreError, WorkOSError] as const; |
| @@ -178,12 +173,6 @@ export class CloudAuthApi extends HttpApiGroup.make("cloudAuth") · 28 unmodified lines | |||
| 178 | error: WorkOSError, | 173 | error: WorkOSError, |
| 179 | }), | 174 | }), |
| 180 | ) | 175 | ) |
| 181 | .add( | ||
| 182 | HttpApiEndpoint.post("switchOrganization", "/auth/switch-organization", { | ||
| 183 | payload: SwitchOrganizationBody, | ||
| 184 | error: WorkOSError, | ||
| 185 | }), | ||
| 186 | ) | ||
| 187 | .add( | 176 | .add( |
| 188 | HttpApiEndpoint.post("createOrganization", "/auth/create-organization", { | 177 | HttpApiEndpoint.post("createOrganization", "/auth/create-organization", { |
| 189 | payload: CreateOrganizationBody, | 178 | payload: CreateOrganizationBody, |
| @@ -301,20 +301,6 @@ export const CloudSessionAuthHandlers = HttpApiBuilder.group( · 300 unmodified lines | |||
| 301 | }; | 301 | }; |
| 302 | }), | 302 | }), |
| 303 | ) | 303 | ) |
| 304 | .handle("switchOrganization", ({ payload }) => | ||
| 305 | Effect.gen(function* () { | ||
| 306 | const workos = yield* WorkOSClient; | ||
| 307 | const session = yield* SessionContext; | ||
| 308 | |||
| 309 | const refreshed = yield* workos.refreshSession( | ||
| 310 | session.sealedSession, | ||
| 311 | payload.organizationId, | ||
| 312 | ); | ||
| 313 | if (refreshed) { | ||
| 314 | (yield* SessionCookies).set("wos-session", refreshed, RESPONSE_COOKIE_OPTIONS); | ||
| 315 | } | ||
| 316 | }), | ||
| 317 | ) | ||
| 318 | .handle("createOrganization", ({ payload }) => | 304 | .handle("createOrganization", ({ payload }) => |
| 319 | Effect.gen(function* () { | 305 | Effect.gen(function* () { |
| 320 | const workos = yield* WorkOSClient; | 306 | const workos = yield* WorkOSClient; |