arrow-express
Version:
Library to bootstrap express applications with zero configuration
27 lines (22 loc) • 572 B
text/typescript
import {RequestError} from "arrow-express";
import Express from 'express';
export type UserContext = {
userId: number
}
/**
* Stub authorization guard
*/
export const AuthorizeGuard = async (req: Express.Request): Promise<UserContext> => {
const authHeader = req.headers.authorization;
const token = parseToken(authHeader);
// Here place your token authorization
if (token === 'token')
return {
userId: 1
};
else
throw new RequestError(401);
};
function parseToken(authHeader: string) {
return (authHeader as string).split(' ')[1];
}