t3-code-android-nightly/.repos/alchemy-effect/packages/better-auth/test/fixtures/probe-worker.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

39 lines
1.3 KiB
TypeScript

/**
* Compile-time probe: `yield* BetterAuth({...})` composes inside a
* `Cloudflare.Worker` impl when the Database layer is provided on the
* effect. This pins the requirement-erasure design — if the Worker's `Req`
* constraint ever rejects the shape, this file breaks the type-check.
*/
import * as Cloudflare from "alchemy/Cloudflare";
import * as Effect from "effect/Effect";
import { HttpServerRequest } from "effect/http/HttpServerRequest";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
import { BetterAuth, Memory } from "../../src/index.ts";
export default class ProbeWorker extends Cloudflare.Worker<ProbeWorker>()(
"ProbeWorker",
{
main: import.meta.url,
},
Effect.gen(function* () {
const auth = yield* BetterAuth({
basePath: "/auth",
emailAndPassword: { enabled: true },
});
return {
fetch: Effect.gen(function* () {
const request = yield* HttpServerRequest;
if (request.url.startsWith("/auth")) {
return yield* auth.fetch;
}
const session = yield* auth
.getSession()
.pipe(Effect.catch((error) => Effect.succeed(null)));
return yield* HttpServerResponse.json({
signedIn: session !== null,
});
}),
};
}).pipe(Effect.provide(Memory())),
) {}