TypeError: Cannot read property 'slice' of undefined

Basically need to retrieve the jwt from the header to logout the user.
console.log("req ", req.get(‘Authorization’)); <-- This is showing as unndefined.

Seems like a client error in sending.

Hi @munish_fauzdar,

logout function needed to be implemented in User Management ticket, is that what you are trying to implement or is it when you are trying to set the application? :slight_smile:

Kanika

So its not particularly this function I have a problem in, its wherever the client is sending the auth bearer token where it gives me an undefined error. I am facing this problem at multiple api requests.


Same problem. I have completed the User-Management ticket but still this happens sometimes.

Many of the tickets, which I have completing are failing integration tests as a result, even though they have been successfully unit tested.

Hello ,
Normally client side (so React side ) should send a user token to delete that user session from session collection . Token should send with help of headers which is Authorization and it should be something like
“Bearer sdfkjFwafj90F*fsd0f023.3249FDFASDLKloremipsum” to our backend server after that we should consume that token .
But client side code is not provide that header logic . So you can not retrieve that token because there is no Header so there is undefined variable. You are trying to slice that undefined variable that’s why you getting this error. Actually we getting this error.This is all about the request which is comes from client side and not included Authorization header.

Also,
In the unit test which is user-management there is nothing about the Authorization to get user token.
All logic in user-management file associated with directly our ./dao/usersDAO file there is nothing associated with api or something else that’s why if you implemented right logic to your usersDAO file you can pass unit test

I hope there’s someone who can solve this problem.Actually, I think if we can get to the frontend(React) code, we’ll solve it.

I think you have described the issue with great detail. thanks for that.

I was able to bypass many a the unit tests having this issue, however the system tests, can’t be passed without the issue being resolved from the front end.

I am facing the exact same issue!

Hello! I have the same issue: /logout expects to receive an Authorization header, but it receives none.
As has been mentioned, it should be fixed in the React code… Does anyone know if there is any work ongoing or plans on doing that? If the react code is hosted openly in a repository (github for example) maybe someone can share a link so it’s possible to try fixing it with a pull request? :slight_smile:
Thanks!

Edit: I actually found the react code in github: https://github.com/mongodb-university/mflix-ui
By just looking at it, the logout request seems to include the Authorization header, but I haven’t run it myself yet (will do when I have a chance).