Template
1
0

feat: add functional authentication

This commit is contained in:
2025-08-12 23:11:08 +02:00
parent f0630d43b7
commit 82d7a0d9cd
74 changed files with 763 additions and 396 deletions

View File

@@ -1,16 +1,41 @@
import { RouteContext } from "@spec/relay";
import { ServerContext, UnauthorizedError } from "@spec/relay";
export function getRequestContext(request: Request): RouteContext {
return {
request,
};
}
import { Session } from "../auth/auth.ts";
import { req } from "./request.ts";
declare module "@spec/relay" {
interface RouteContext {
interface ServerContext {
/**
* Current request instance being handled.
*/
request: Request;
/**
* Get request session instance.
*/
session: Session;
/**
* Get account id from session, throws an error if the request
* does not have a valid session.
*/
accountId: string;
}
}
export function getRequestContext(request: Request): ServerContext {
return {
request,
get session(): Session {
if (req.session === undefined) {
throw new UnauthorizedError();
}
return req.session;
},
get accountId() {
return this.session.accountId;
},
};
}