I am doing auth using passportjs, but when the client tries to pull the token, it gives an error.
import jwt from "express-jwt"
const getTokenFromHeaders = (req) => {
const {headers : {authorization}} = req
if(authorization && authorization.spilt(' ')[0] === 'Token' ){
return authorization.split(' ')[1]
}
return null
}
this console
file:///C:/Users/atala/Desktop/atalayapp-main/backend/middleware/auth/auth.js:3
const {headers : {authorization}} = req
^
TypeError: Cannot read properties of undefined (reading 'headers')
at getTokenFromHeaders (file:///C:/Users/Desktop/atalayapp-main/backend/middleware/auth/auth.js:3:41)
at file:///C:/Users/Desktop/atalayapp-main/backend/middleware/auth/auth.js:15:20
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)
> Blockquote