[Vuejs]-Authentication using Jwt and nodejs

0👍

I am not sure if the web app you are building is just for fun or you are planning to use it in production, if so I will suggest you not to use localStorage to save the token. A JWT needs to be stored in a safe place inside the user’s browser.

If you store it inside localStorage, it’s accessible by any script inside your page (which is as bad as it sounds as an XSS attack can let an external attacker get access to the token).

Don’t store it in local storage (or session storage). If any of the 3rd part scripts you include in your page gets compromised, it can access all your users’ tokens.

The JWT needs to be stored inside an HttpOnly cookie, a special kind of cookie that’s only sent in HTTP requests to the server, and it’s never accessible (both for reading or writing) from JavaScript running in the browser.

Source:

  1. https://auth0.com/docs/security/store-tokens
  2. https://logrocket.com/blog/jwt-authentication-best-practices/
  3. https://blog.usejournal.com/sessionless-authentication-withe-jwts-with-node-express-passport-js-69b059e4b22c

Now going back to the original question, I see

import Navbar from '@/components/Navbar'

But I don’t you use it in the template, also can you post the vue component in which you are having issues with?

Leave a comment