Nuxt.js Authenticate with JWT

in #nuxt6 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')
Sort:  

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!

Coin Marketplace

STEEM 0.19
TRX 0.19
JST 0.033
BTC 91239.44
ETH 3087.28
USDT 1.00
SBD 2.81