Nuxt.js Authenticate with JWT

in nuxt •  6 years ago 

[Login]

  1. login process with passport
    --> req.user is generated automatically by passport
  2. create route for '/auth/token' for get jwt token with req.user
  3. create nuxtServerInit for fetching token and set token to store.state
  4. check authenticated by middleware

[Logout]

  1. create route for '/auth/logout' includes followings:
    router.get('/auth/logout', (req,res)=>{
    req.logout()
    req.redirect(>>front main url or sign-in url<<)
    ...
    })
  2. delete token and other user-info from state.store
  3. window.location.replace( BACKEND+'/auth/logout')
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @dirmich! You received a personal award!

1 Year on Steemit

Click here to view your Board of Honor

Do not miss the last post from @steemitboard:

Saint Nicholas challenge for good boys and girls

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @dirmich! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!