History

Web clients scope by the URL org; drop cookie-based org switching (#1000)

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).

Rhys Sullivan committed 5 months ago

Commit 1f9bfe01 parent 58e23e814 files · +233 −214Browse files

Showing the changes to apps/cloud/src/auth (2 of 14 files). Show all

Unified · Split

2 files
  1. apps/cloud/src/auth/api.ts +0 −11
  2. apps/cloud/src/auth/handlers.ts +0 −14
apps/cloud/src/auth/api.ts+0−11
@@ -34,10 +34,6 @@ const AuthOrganizationsResponse = Schema.Struct({ · 33 unmodified lines
3434 activeOrganizationId: Schema.NullOr(Schema.String),
3535 });
3636
37−const SwitchOrganizationBody = Schema.Struct({
38− organizationId: Schema.String,
39−});
40−
4137 const CreateOrganizationBody = Schema.Struct({
4238 name: Schema.String,
4339 });
@@ -143,7 +139,6 @@ export const AUTH_PATHS = { · 99 unmodified lines
143139 login: "/api/auth/login",
144140 logout: "/api/auth/logout",
145141 callback: "/api/auth/callback",
146− switchOrganization: "/api/auth/switch-organization",
147142 } as const;
148143
149144 const AuthErrors = [UserStoreError, WorkOSError] as const;
@@ -178,12 +173,6 @@ export class CloudAuthApi extends HttpApiGroup.make("cloudAuth") · 28 unmodified lines
178173 error: WorkOSError,
179174 }),
180175 )
181− .add(
182− HttpApiEndpoint.post("switchOrganization", "/auth/switch-organization", {
183− payload: SwitchOrganizationBody,
184− error: WorkOSError,
185− }),
186− )
187176 .add(
188177 HttpApiEndpoint.post("createOrganization", "/auth/create-organization", {
189178 payload: CreateOrganizationBody,
apps/cloud/src/auth/handlers.ts+0−14
@@ -301,20 +301,6 @@ export const CloudSessionAuthHandlers = HttpApiBuilder.group( · 300 unmodified lines
301301 };
302302 }),
303303 )
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− )
318304 .handle("createOrganization", ({ payload }) =>
319305 Effect.gen(function* () {
320306 const workos = yield* WorkOSClient;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t