mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-21 04:16:38 +00:00
added utils for unauth, verify, and response
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
export * from "./unauthorizedResponse";
|
||||
export * from "./verifySession";
|
||||
|
||||
import { Lucia, TimeSpan } from "lucia";
|
||||
import { DrizzleSQLiteAdapter } from "@lucia-auth/adapter-drizzle";
|
||||
import db from "@server/db";
|
||||
|
||||
6
server/auth/unauthorizedResponse.ts
Normal file
6
server/auth/unauthorizedResponse.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
import createHttpError from "http-errors";
|
||||
|
||||
export function unauthorized(msg?: string) {
|
||||
return createHttpError(HttpCode.UNAUTHORIZED, msg || "Unauthorized");
|
||||
}
|
||||
9
server/auth/verifySession.ts
Normal file
9
server/auth/verifySession.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Request } from "express";
|
||||
import { lucia } from "@server/auth";
|
||||
|
||||
export async function verifySession(req: Request) {
|
||||
const res = await lucia.validateSession(
|
||||
req.cookies[lucia.sessionCookieName],
|
||||
);
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user