Template
1
0

feat: add procedure to relay

This commit is contained in:
2025-08-18 01:05:23 +02:00
parent 81108e0a60
commit d322138502
12 changed files with 346 additions and 48 deletions

View File

@@ -1,4 +1,6 @@
import { ServerContext, UnauthorizedError } from "@spec/relay";
import { ServerContext } from "@spec/relay";
import type { Sockets } from "~libraries/socket/sockets.ts";
import { Session } from "../auth/auth.ts";
import { req } from "./request.ts";
@@ -11,15 +13,25 @@ declare module "@spec/relay" {
request: Request;
/**
* Get request session instance.
* Is the request authenticated.
*/
session: Session;
isAuthenticated: boolean;
/**
* Get account id from session, throws an error if the request
* does not have a valid session.
*/
accountId: string;
/**
* Get request session instance.
*/
session: Session;
/**
* Sockets instance attached to the server.
*/
sockets: Sockets;
}
}
@@ -27,15 +39,20 @@ export function getRequestContext(request: Request): ServerContext {
return {
request,
get session(): Session {
if (req.session === undefined) {
throw new UnauthorizedError();
}
return req.session;
get isAuthenticated(): boolean {
return req.isAuthenticated;
},
get accountId() {
return this.session.accountId;
},
get session(): Session {
return req.session;
},
get sockets(): Sockets {
return req.sockets;
},
};
}