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 */
7import * as Cloudflare from "alchemy/Cloudflare";
8import * as Effect from "effect/Effect";
9import { HttpServerRequest } from "effect/http/HttpServerRequest";
10import * as HttpServerResponse from "effect/http/HttpServerResponse";
11import { BetterAuth, Memory } from "../../src/index.ts";
12
13export 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) {}