Skip to Main Content
Hands-on Nuxt.js Web Development
book

Hands-on Nuxt.js Web Development

by Lau Tiam Kok Kok Lau
August 2020
Beginner to intermediate content levelBeginner to intermediate
698 pages
12h 2m
English
Packt Publishing
Content preview from Hands-on Nuxt.js Web Development
Creating User Logins and API Authentication

In the last two chapters, we started working on session and JSON Web Token (JWT) authentication in Nuxt apps. We used sessions for authentication in Chapter 10, Adding a Vuex Store, to exercise nuxtServerInit. Then we used sessions and tokens together for authentication in Chapter 11, Writing Route Middlewares and Server Middlewares, to exercise per-route middleware, for example:

// store/index.jsnuxtServerInit({ commit }, { req }) {  if (req.ctx.session && req.ctx.session.authUser) {    commit('setUser', req.ctx.session.authUser)  }}// middleware/token.jsexport default async ({ store, error }) => {  if (!store.state.auth.token) {    // handle error  } axios.defaults.headers.common['Authorization'] = Bearer: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Test-Driven JavaScript Development

Test-Driven JavaScript Development

Ravi Kumar Gupta
Front-End Development Projects with Vue.js

Front-End Development Projects with Vue.js

Raymond Camden, Hugo Di Francesco, Clifford Gurney, Philip Kirkbride, Maya Shavin

Publisher Resources

ISBN: 9781789952698Supplemental Content