import { Context, Schema } from "effect" import { HttpApiMiddleware, HttpApiSecurity } from "effect/unstable/httpapi" import type { User } from "../domain/User.ts" export class CurrentUser extends Context.Service()("acme/HttpApi/Authorization/CurrentUser") {} export class Unauthorized extends Schema.TaggedError()( "Unauthorized", { message: Schema.String }, // You can define error status codes directly on the error class { httpApiStatus: 401 } ) {} export class Authorization extends HttpApiMiddleware.Service()("acme/HttpApi/Authorization", { // This middleware requires clients to also provide an implementation, to // inject a api key requiredForClient: true, // Middleware can optionally define security schemes, which are used to // generate OpenAPI docs and decode credientials from incoming requests for // you. security: { bearer: HttpApiSecurity.bearer }, // Middlware can specify errors that it may raise error: Unauthorized }) {}