mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-24 05:05:20 -04:00
16 lines
504 B
TypeScript
16 lines
504 B
TypeScript
import jwt from './jwt.ts';
|
|
import type { Request } from 'express';
|
|
import type { User } from '../src/user.ts';
|
|
|
|
export default ({ cookies, headers }: Request): User | undefined => {
|
|
if (headers.authorization && headers.authorization.startsWith('Bearer ')) {
|
|
return jwt.validate(headers.authorization.substring(7)) as User | undefined;
|
|
}
|
|
|
|
if (cookies.token && cookies.token !== 'null') {
|
|
return jwt.validate(cookies.token) as User | undefined;
|
|
}
|
|
|
|
return undefined;
|
|
};
|