nuxt-auth-server-init
v1.0.3
Published
nuxt-auth plugin providing the ability to request data only for authorized users
Downloads
59
Readme
nuxt-auth-server-init
nuxt-auth plugin that provides the ability to request data only for authorized users.
Installation
$ npm install nuxt-auth-server-init
// nuxt.config.js
export default {
modules: [
'nuxt-auth-server-init',
'@nuxtjs/auth',
],
}
Important: the plugin declaration must come before the nuxt-auth module declaration.
Usage
By analogy with nuxtServerInit, you need to create an action in the store - nuxtAuthServerInit:
// store/index.js
export const actions = {
async nuxtAuthServerInit(store, context) {
await store.dispatch('some-action/getData')
}
}
this action will be called on the server side only if the user is logged in ($auth.loggedIn === true), also the action is called after login ($auth.login()).
Thus, we can guaranteed to receive data that is needed only for authorized users.