# Authorization is undefined resulting undefined even after adding token in header

**URL:** <https://community.postman.com/t/authorization-is-undefined-resulting-undefined-even-after-adding-token-in-header/74795>\
**Category:** Help Hub\
**Tags:** authentication, bearer-token\
**Created:** [February 3, 2025, 4:47am UTC](https://community.postman.com/t/authorization-is-undefined-resulting-undefined-even-after-adding-token-in-header/74795 "2025-02-03T04:47:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rchaudhary18](https://avatars.discourse-cdn.com/v4/letter/r/c4cdca/32.png) [@rchaudhary18](https://community.postman.com/u/rchaudhary18)\
**Post date:** [February 3, 2025, 4:47am UTC](https://community.postman.com/t/authorization-is-undefined-resulting-undefined-even-after-adding-token-in-header/74795/1 "2025-02-03T04:47:11Z")

</div>

Hi, i am new to postman. I am adding bearer token in authorization during the http request but on server side while reading, i am getting it undefined.

 ![Screenshot (11)](https://us1.discourse-cdn.com/getpostman/original/3X/c/1/c1c037732de4a1ccc1d431e818e3655bb70caaee.png)

here is the implementation:

```auto
const jwt = require('jsonwebtoken');
const jwtAuthMiddleware = (req, res, next)=>{
    //check header for authorization:
    const auth = req.header.authorization;
    if(!auth) return res.status(401).json({error: 'token not found here'});
//Extract the jwt token from the request
const token = req.header.authorization.split(' ')[1];
if(!token) return res.status(401).json({error: 'Unauthorized'});
try{
    //verify JWT token
    const decoded = jwt.verify(token, process.env.JWT_SECRET);
    //attaching a key in request as user with value as decoded which is the jwt token payload received after verification
    req.user = decoded;
    next();

}catch(err){
    //throw err;
    res.status(401).json({error: 'Unauthorized'});
}

}

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [February 3, 2025, 12:04pm UTC](https://community.postman.com/t/authorization-is-undefined-resulting-undefined-even-after-adding-token-in-header/74795/2 "2025-02-03T12:04:43Z")

</div>

Hey @rchaudhary18 👋

Welcome to the Postman Community! :postman:

What is the console output of this?

> [@rchaudhary18](#):
>
> `const token = req.header.authorization.split(' ')[1];`

I would expect that `token` value in the request, to have `Bearer` and a space in-front of it.

For example:

```auto
Authorization: Bearer abc1234

```

If the `Bearer` keyword or the space is missing, the `.split(' ')[1]` statement would fail to extract the token correctly. I haven’t run your code so I wouldn’t know for sure. 😬
