nuxt-auth-server-init

1.0.3 • Public • Published

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.

Package Sidebar

Install

npm i nuxt-auth-server-init

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

2.64 kB

Total Files

4

Last publish

Collaborators

  • 17axah