Bug in users.controller.js

I’m trying to logout manually in the mflix website and I’m getting this error:
POST http://localhost:5000/api/v1/user/logout 500 (Internal Server Error)

TypeError: Cannot read property 'slice' of undefined
    at _callee6$ (mflix-js/src/api/users.controller.js:123:23)
    at tryCatch (mflix-js/node_modules/regenerator-runtime/runtime.js:45:40)
    at Generator.invoke [as _invoke] (mflix-js/node_modules/regenerator-runtime/runtime.js:271:22)
    at Generator.prototype.<computed> [as next] (mflix-js/node_modules/regenerator-runtime/runtime.js:97:21)
    at asyncGeneratorStep (mflix-js/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
    at _next (mflix-js/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
    at mflix-js/node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
    at new Promise (<anonymous>)
    at mflix-js/node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12
    at logout (mflix-js/src/api/users.controller.js:457:24)
POST /api/v1/user/logout 500 24.119 ms - 2

the code in these lines is:

  static async logout(req, res) {
    try {
      ---> const userJwt = req.get("Authorization").slice("Bearer ".length)
      const userObj = await User.decoded(userJwt)

(btw, I’m getting a similar error when trying to add new comment.)
Does anyone have an idea how to fix it?

1 Like

Hey Rafael,
have you solved the problem??

Hi @Adeeb_Akhtar ,
As far as I can remember, I just continued with the course without solving this problem.
I think you can skip it and finish the course (get 100% score) without solving this issue.
Good luck,

Hi @Adeeb_Akhtar, welcome to the community.
Seems like there was no Authorization header present in the request. To debug this, try running:


before the try block.

And in case it gives undefined as output, I would recommend you to clear your browser cookies, cache, and all related site data from the browser.
And try again by login/signup and then logout.
I hope this helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

1 Like