15 lines
458 B
TypeScript
15 lines
458 B
TypeScript
import { makeParameterModifier } from "../Router.ts";
|
|
|
|
export type AuthType = 'raw' | 'jwt';
|
|
|
|
export function auth(type: AuthType = 'jwt') {
|
|
return makeParameterModifier(req => {
|
|
let res = req.headers.authorization;
|
|
if (typeof res !== 'string') return undefined;
|
|
if (res.startsWith('Bearer')) res = res.substring(6).trimStart();
|
|
|
|
if (type === 'jwt') throw new Error('JWT is not supported.');
|
|
|
|
return res;
|
|
});
|
|
} |