pluralchat / src /lib /server /api /authPlugin.ts
nsarrazin's picture
refactor: new API & universal load functions (pt. 2) (#1847)
612f16b unverified
import Elysia from "elysia";
import { authenticateRequest } from "../auth";
export const authPlugin = new Elysia({ name: "auth" }).derive(
{ as: "scoped" },
async ({
headers,
cookie,
}): Promise<{
locals: App.Locals;
}> => {
const auth = await authenticateRequest(
{ type: "elysia", value: headers },
{ type: "elysia", value: cookie },
true
);
return {
locals: {
user: auth?.user,
sessionId: auth?.sessionId,
isAdmin: auth?.isAdmin,
},
};
}
);