This repository has been archived on 2025-04-04. You can view files and clone it, but cannot push or open issues or pull requests.
mojotrollz-app/api/middleware/authenticator.ts

31 lines
660 B
TypeScript

import { Request, Response, NextFunction } from 'express'
import jwt from 'jsonwebtoken'
import config from '../../config'
export const authenticator = function (
req: Request,
_res: Response,
next: NextFunction
): any {
req.user = null
const token = req.headers.authorization
if (token) {
// verifies secret and checks if the token is expired
jwt.verify(
token.replace(/^Bearer\s/, ''),
config.server.authSecret,
function (err, _decoded) {
// TODO
if (err) {
req.user = 'bo'
} else {
req.user = 'yo'
}
}
)
}
return next()
}
export default authenticator