@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 39 lines 1.3 KB
Raw
1 /**
2 * Compile-time probe: `yield* BetterAuth({...})` composes inside a
3 * `Cloudflare.Worker` impl when the Database layer is provided on the
4 * effect. This pins the requirement-erasure design — if the Worker's `Req`
5 * constraint ever rejects the shape, this file breaks the type-check.
6 */
7 import * as Cloudflare from "@alchemy.run/cloudflare";
8 import * as Effect from "effect/Effect";
9 import { HttpServerRequest } from "effect/http/HttpServerRequest";
10 import * as HttpServerResponse from "effect/http/HttpServerResponse";
11 import { BetterAuth, Memory } from "../../src/index.ts";
12
13 export default class ProbeWorker extends Cloudflare.Worker<ProbeWorker>()(
14 "ProbeWorker",
15 {
16 main: import.meta.url,
17 },
18 Effect.gen(function* () {
19 const auth = yield* BetterAuth({
20 basePath: "/auth",
21 emailAndPassword: { enabled: true },
22 });
23
24 return {
25 fetch: Effect.gen(function* () {
26 const request = yield* HttpServerRequest;
27 if (request.url.startsWith("/auth")) {
28 return yield* auth.fetch;
29 }
30 const session = yield* auth
31 .getSession()
32 .pipe(Effect.catch((error) => Effect.succeed(null)));
33 return yield* HttpServerResponse.json({
34 signedIn: session !== null,
35 });
36 }),
37 };
38 }).pipe(Effect.provide(Memory())),
39 ) {}