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

main
ts 23 lines 797 Bytes
Raw
1 /** The application owns the API, including Git's groups and its middleware. */
2 import * as Git from "@alchemy.run/git";
3 import * as Effect from "effect/Effect";
4 import * as HttpApi from "effect/http-api/HttpApi";
5 import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder";
6 import { Session, Unauthorized } from "./auth.ts";
7 import { Authentication } from "./middleware.ts";
8 import { AppRoutes } from "./routes.ts";
9
10 export class AppApi extends HttpApi.make("app")
11 .addHttpApi(Git.Api)
12 .add(AppRoutes)
13 .middleware(Authentication) {}
14
15 export const MeLive = HttpApiBuilder.group(AppApi, "app", (h) =>
16 h.handle("me", () =>
17 Effect.gen(function* () {
18 const { user } = yield* Session;
19 if (user === null) return yield* new Unauthorized();
20 return user;
21 }),
22 ),
23 );