Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
Vuejs Authentication JWT VUEX

Hi i do vue authentication with jwt and vuex, and works well but i need to load token and user when i refresh page. i find online this code store.dispatch('auth/attemptAuthtoken', localStorage.getItem('authToken'))and works good but works only in main.js . I need to put it in index.js (main file of store) but if i use it i have problem with store/dispatch etc.
I try to import store but i've problem too.
enter image description here enter image description here
Someone can help me to fix it? (I started very recently to use vue / vuex)
main.js

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import store from './store'

store.dispatch('auth/attemptAuthtoken', localStorage.getItem('authToken'))
store.dispatch('auth/attemptUser', JSON.parse (localStorage.getItem('user')))

axios.defaults.baseURL = 'https://**********/'

createApp(App).use(store).use(router).mount('#app')

index.js

import { createStore } from 'vuex'
import auth from './auth.js'




export default createStore({
  state: {
  },
  mutations: {
  },
  actions: {
  },
  modules: {
    auth
  }
})

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!