crm-api-template-generator/backend/middleware/authentication.js

27 lines
610 B
JavaScript
Raw Normal View History

2023-11-29 20:05:48 +00:00
const CustomError = require('../errors')
const authorization = async (req, res, next) => {
const authHeader = req.headers.authorization
if (!authHeader) {
throw new CustomError.BadRequestError('Authorization not found into header!')
}
const [, token] = authHeader.split(" ");
if (!token) {
throw new CustomError.BadRequestError('Authorization token not found into header!')
}
if (token != process.env.TOKEN){
throw new CustomError.UnauthorizedError('Authorization token Invalid')
}
next()
}
module.exports = {
authorization,
}