History

cloud/local/examples: thread per-user ScopeStack through HTTP + MCP

- cloud: resolves userId from the authenticated session and builds a [userOrgScope, orgScope] stack via createScopedExecutor(userId, orgId, orgName). userId threaded through execution-stack, mcp-session, and MCP dispatch init. - cloud env refactor: deletes the lazy Proxy apps/cloud/src/env.ts in favor of cloudflare:workers env imported at call sites; adds env-augment.d.ts to type secrets not present in generated wrangler types. - cloud/server.ts: env-guarded OTEL wiring (skips instrument() when AXIOM_TOKEN absent); captures rawFetch before instrument() mutates it so dev requests still land on the Hono app. - cloud/services/db.ts: prefers DATABASE_URL over the hyperdrive proxy so local dev works without the tunnel. - vite.config.ts: devCrashGuard plugin that prints uncaught Worker errors with a stable exit. - hosts/mcp: optional debug flag surfaces verbose session logging, wired up from cloud mcp-session. - local/examples/marketing: migrated to scopes: [scope].

Rhys Sullivan committed 6 months ago

Commit d4e311e1 parent 427699c25 files · +320 −174Browse files

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

Unified · Split

2 files
  1. apps/cloud/src/auth/handlers.ts +2 −2
  2. apps/cloud/src/auth/workos.ts +4 −4
apps/cloud/src/auth/handlers.ts+2−2
@@ -6,9 +6,9 @@ import { AUTH_PATHS, CloudAuthApi, CloudAuthPublicApi } from "./api"; · 5 unmodified lines
66 import { SessionContext } from "./middleware";
77 import { UserStoreService } from "./context";
88 import { authorizeOrganization } from "./authorize-organization";
9+import { env } from "cloudflare:workers";
910 import { WorkOSError } from "./errors";
1011 import { WorkOSAuth } from "./workos";
11−import { server } from "../env";
1212
1313 const COOKIE_OPTIONS = {
1414 path: "/",
@@ -40,7 +40,7 @@ export const CloudAuthPublicHandlers = HttpApiBuilder.group( · 25 unmodified lines
4040 // Use the explicit public site URL — in dev, the request's Host
4141 // header points at the internal proxy target, not the public URL
4242 // WorkOS needs to redirect back to.
43− const origin = server.VITE_PUBLIC_SITE_URL;
43+ const origin = env.VITE_PUBLIC_SITE_URL ?? "";
4444 const url = workos.getAuthorizationUrl(`${origin}${AUTH_PATHS.callback}`);
4545 return HttpServerResponse.redirect(url, { status: 302 });
4646 }),
apps/cloud/src/auth/workos.ts+4−4
@@ -2,10 +2,10 @@ · 1 unmodified line
22 // WorkOS AuthKit — Effect-native sealed session management
33 // ---------------------------------------------------------------------------
44
5+import { env } from "cloudflare:workers";
56 import { Context, Effect, Layer } from "effect";
67 import { WorkOS } from "@workos-inc/node/worker";
78 import { WorkOSError, tryPromiseService, withServiceLogging } from "./errors";
8−import { server } from "../env";
99
1010 const COOKIE_NAME = "wos-session";
1111
@@ -14,9 +14,9 @@ const COOKIE_NAME = "wos-session"; · 2 unmodified lines
1414 // ---------------------------------------------------------------------------
1515
1616 const make = Effect.gen(function* () {
17− const apiKey = server.WORKOS_API_KEY;
18− const clientId = server.WORKOS_CLIENT_ID;
19− const cookiePassword = server.WORKOS_COOKIE_PASSWORD;
17+ const apiKey = env.WORKOS_API_KEY;
18+ const clientId = env.WORKOS_CLIENT_ID;
19+ const cookiePassword = env.WORKOS_COOKIE_PASSWORD;
2020
2121 if (!cookiePassword || cookiePassword.length < 32) {
2222 return yield* Effect.die(new Error("WORKOS_COOKIE_PASSWORD must be at least 32 characters"));