feat: add procedure to relay
This commit is contained in:
@@ -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;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user