The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { BetterAuth } from "@alchemy.run/better-auth"; |
| 2 | import * as Config from "effect/Config"; |
| 3 | import * as Context from "effect/Context"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as Layer from "effect/Layer"; |
| 6 | import * as Option from "effect/Option"; |
| 7 | import * as Redacted from "effect/Redacted"; |
| 8 | |
| 9 | export const makeAuth = Effect.gen(function* () { |
| 10 | const baseURL = yield* Config.String("AUTH_BASE_URL").pipe(Config.option); |
| 11 | const githubEnabled = yield* Config.Boolean("GITHUB_ENABLED").pipe(Config.withDefault(false)); |
| 12 | const github = githubEnabled |
| 13 | ? { |
| 14 | clientId: yield* Config.String("GITHUB_CLIENT_ID"), |
| 15 | clientSecret: Redacted.value(yield* Config.Redacted("GITHUB_CLIENT_SECRET")), |
| 16 | } |
| 17 | : undefined; |
| 18 | |
| 19 | return yield* BetterAuth({ |
| 20 | basePath: "/api/auth", |
| 21 | emailAndPassword: { enabled: true }, |
| 22 | baseURL: Option.getOrUndefined(baseURL), |
| 23 | socialProviders: github ? { github } : {}, |
| 24 | }); |
| 25 | }); |
| 26 | |
| 27 | export class Auth extends Context.Service<Auth, Effect.Success<typeof makeAuth>>()("app/Auth") { |
| 28 | static readonly layer = Layer.effect(Auth, makeAuth); |
| 29 | } |