question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use vuex-rest-api with nuxt.js auth-module

See original GitHub issue

Hey I have the following issue…

I need nuxt auth-module to work with that package but at the point of creation I cant pass any axios instance, and thre is no global one. The result is that I get 401 response as I cant use the correct axios instance with the auth logic. Any idea?

in Nuxtj.s I create a store

import userStore from './users'

const createStore = () => {
  return new Vuex.Store({
    state: {
    },
    mutations: {
    },
    modules: {
      users: userStore
    }
  })
}

export default createStore

users store

import Vapi from 'vuex-rest-api'

const userStore = new Vapi({
  baseURL: '/api',
  state: {
    users: [],
    groups: []
  }
})
  .get({
    action: 'getUsers',
    property: 'users',
    path: '/users/getUsersTableData'
  })
  .get({
    action: 'getGroups',
    property: 'groups',
    path: '/users/getGroupsTableData'
  })

export default userStore.getStore()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
appinteractivecommented, Aug 17, 2018

found a solution for now:

I can register it by using the registerModule() method on the store, inside a plugin that is loaded after the axios initialization.

plugins/init-store-modules.js

export default async ({store, app}) => {
  await store.dispatch('initStoreModules', {store: store, axios: app.$axios})
}

store/index.js

import Vuex from 'vuex'
import userStore from './users'

const createStore = () => {
  return new Vuex.Store({
    state: {
    },
    mutations: {
    },
    // modules: {
    //   users: userStore()
    // },
    actions: {
      async initStoreModules ({state}, {store, axios}) {
        await store.registerModule('users', userStore(axios));
      }
    }
  })
}

export default createStore

You could also register that inside the plugin but I like to have the module registration inside the store.

@christianmalek Maybe that should be added to the readme with an example or similar.

1reaction
christianmalekcommented, Dec 5, 2018

@juandl But you don’t pass any specific axios instance in your code example which was necessary for nuxt-auth @appinteractive, doesn’t it? So how does this work?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setup - nuxt auth docs
Check the Nuxt.js documentation for more information about installing and using modules in Nuxt.js. ... When adding auth-module to a new Nuxt ...
Read more >
How To Implement Authentication in a Nuxt.js App
In this tutorial, you'll implement authentication in a Nuxt.js app using the Auth module. For the purpose of this tutorial we'll be using...
Read more >
Nuxt.js And Express.js Authentication with Auth Module and JWT
Hi, today we want to build an authentication app with Nuxt.js and Express.js, we'll focus on the front-end, and nuxt auth module and...
Read more >
How to add authentication to your universal Nuxt app using ...
Installation of axios and auth modules; Configuration needed in nuxt.config.js; Using the state from auth module to check if user is logged ...
Read more >
Authentication in Nuxt app - BlowStack
npm i @nuxtjs/auth After installation add auth module to the nuxt config. Notice that this module requires axios to work so if you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found