mirror of
https://github.com/detleph/server.git
synced 2026-09-06 07:56:19 +02:00
Add methods for requiring more specific levels of teamleader auth
+ Add AuthError
This commit is contained in:
@@ -6,13 +6,17 @@ import { authClient } from "../../lib/redis";
|
||||
import jwt, { JsonWebTokenError, JwtPayload } from "jsonwebtoken";
|
||||
import prisma from "../../lib/prisma";
|
||||
|
||||
const JWT_SECRET = process.env.JWT_SECRET || "secret";
|
||||
const JWT_SECRET = process.env.JWT_SECRET;
|
||||
|
||||
export const verifyAuthorizationFormat = (authorization: string) => /^Bearer .+$/.test(authorization);
|
||||
|
||||
export const getBearerToken = (authorization: string) => authorization.slice(7);
|
||||
|
||||
export const requireAuthentication = async (req: Request, res: Response, next: NextFunction) => {
|
||||
if (!JWT_SECRET) {
|
||||
throw new Error("JWT_SECRET not set");
|
||||
}
|
||||
|
||||
const { authorization } = req.headers;
|
||||
|
||||
if (!authorization) {
|
||||
|
||||
Reference in New Issue
Block a user