By Developers, For Developers
| PDF Pg | Paper Pg | Type | Description | Fixed on | Comments |
|---|---|---|---|---|---|
| 186 | ERROR | There is a refactoring of lib/token-auth.js on this page that breaks the JWT authentication. We are attempting to handle corrupted JWT’s with a 401, which is done, but now even authentic JWT’s are being responded to with 401. If you look at the code in token-auth.js, you will see that “”“let user = findUserByToken(payload)”“” under the try/catch is an unused variable. I’m not sure what the intent is here, but there is clearly an issue. I’m usually a fan of these books, but this one has been really short and extremely basic for what I expected for a $25 ebook. | 2019-10-31 | Hi Michael, thanks for reaching out! I double checked pages 106–109 in the PDF (perhaps the page number you mention — 186 — is from the ebook?). It looks like you might have applied one of the steps to a similar looking region; the user variable definitely shouldn't be unused. What do you have immediately following that line? Here's what it should be by midway through page 109 in the PDF version: \n \n``` \nlet tokenAuth = (req, res, next) => { \n let header = req.headers.authorization || ''; \n let [type, token] = header.split(' '); \n \n if (type === 'Bearer') { \n let payload; \n try { \n payload = jwt.verify(token, signature); \n } catch(err) { \n res.sendStatus(401); \n return; \n } \n \n let user = findUserByToken(payload); \n if (user) { \n req.user = user; \n } else { \n res.sendStatus(401); \n return; \n } \n } \n \n next(); \n}; \n``` \n \nMy guess is you moved the if-else statement we added on page 107 that comes right after "let user = findUserByToken(payload)" and turned it into the try-catch block we add on page 109, since the code looks quite similar and that code block omits the remaining code with a "[...]". \n \nWould you check if that gets you back on track? |