Your IP : 216.73.216.91


Current Path : /var/node/inatote/qa_inatote/helpers/
Upload File :
Current File : /var/node/inatote/qa_inatote/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
}