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
34 activeOrganizationId: Schema.NullOr(Schema.String),34 activeOrganizationId: Schema.NullOr(Schema.String),
35});35});
36 36
37const SwitchOrganizationBody = Schema.Struct({
38 organizationId: Schema.String,
39});
40
41const CreateOrganizationBody = Schema.Struct({37const 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
149const AuthErrors = [UserStoreError, WorkOSError] as const;144const 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,
apps/cloud/src/auth/handlers.ts+0−14
@@ -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;

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