| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder"; |
| 3 | import { Session, Unauthorized } from "./auth.ts"; |
| 4 | /** The application owns the API, including Git's groups and its middleware. */ |
| 5 | import * as Git from "alchemy/Git"; |
| 6 | import * as HttpApi from "effect/http-api/HttpApi"; |
| 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 | ); |