| Current Path : /var/node/inatote/Inatote-Backend/helpers/ |
| Current File : //var/node/inatote/Inatote-Backend/helpers/validate-headers.js |
import { AuthorizationTokenError, ApiTokenError } from "./errors.js"
import jwt from 'jsonwebtoken'
export default function validateHeaders(headers, isToken) {
var verify = undefined;
if (headers == undefined) {
throw new ApiTokenError("Headers not found.")
}
if (!headers['x-api-token']) {
throw new ApiTokenError("Api token is missing.")
} else if (headers['x-api-token'] != ")(*&^!@#$%ghjklfdsa") {
throw new ApiTokenError("Invalid api token.")
}
if (isToken) {
verify = {}
// if (!headers['token'] || headers['token'] == undefined)
// throw new AuthorizationTokenError("Token is missing.")
// try {
// verify = jwt.verify(headers['token'], 'secret')
// if (!verify)
// throw new AuthorizationTokenError("Invalid authorization token.")
// } catch (e) {
// throw new AuthorizationTokenError("Invalid authorization token.")
// }
}
return verify
}