1import * as Effect from "effect/Effect";
2import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder";
3import { Session, Unauthorized } from "./auth.ts";
4/** The application owns the API, including Git's groups and its middleware. */
5import * as Git from "alchemy/Git";
6import * as HttpApi from "effect/http-api/HttpApi";
7import { Authentication } from "./middleware.ts";
8import { AppRoutes } from "./routes.ts";
9
10export class AppApi extends HttpApi.make("app")
11 .addHttpApi(Git.Api)
12 .add(AppRoutes)
13 .middleware(Authentication) {}
14
15export 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);