mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
examples(auth-jwt): use named store export to prevent warning (#5775)
This commit is contained in:
parent
a764e1f90d
commit
0e48eb634b
@ -1,32 +1,26 @@
|
||||
import Vuex from 'vuex'
|
||||
|
||||
const cookieparser = process.server ? require('cookieparser') : undefined
|
||||
|
||||
const createStore = () => {
|
||||
return new Vuex.Store({
|
||||
state: {
|
||||
auth: null
|
||||
},
|
||||
mutations: {
|
||||
setAuth(state, auth) {
|
||||
state.auth = auth
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
nuxtServerInit({ commit }, { req }) {
|
||||
let auth = null
|
||||
if (req.headers.cookie) {
|
||||
const parsed = cookieparser.parse(req.headers.cookie)
|
||||
try {
|
||||
auth = JSON.parse(parsed.auth)
|
||||
} catch (err) {
|
||||
// No valid cookie found
|
||||
}
|
||||
}
|
||||
commit('setAuth', auth)
|
||||
export const state = () => {
|
||||
return {
|
||||
auth: null
|
||||
}
|
||||
}
|
||||
export const mutations = {
|
||||
setAuth(state, auth) {
|
||||
state.auth = auth
|
||||
}
|
||||
}
|
||||
export const actions = {
|
||||
nuxtServerInit({ commit }, { req }) {
|
||||
let auth = null
|
||||
if (req.headers.cookie) {
|
||||
const parsed = cookieparser.parse(req.headers.cookie)
|
||||
try {
|
||||
auth = JSON.parse(parsed.auth)
|
||||
} catch (err) {
|
||||
// No valid cookie found
|
||||
}
|
||||
}
|
||||
})
|
||||
commit('setAuth', auth)
|
||||
}
|
||||
}
|
||||
|
||||
export default createStore
|
||||
|
Loading…
Reference in New Issue
Block a user