examples(auth-jwt): use named store export to prevent warning (#5775)

This commit is contained in:
Alexandre David 2019-05-21 18:56:37 +01:00 committed by Pooya Parsa
parent a764e1f90d
commit 0e48eb634b

View File

@ -1,32 +1,26 @@
import Vuex from 'vuex'
const cookieparser = process.server ? require('cookieparser') : undefined const cookieparser = process.server ? require('cookieparser') : undefined
const createStore = () => { export const state = () => {
return new Vuex.Store({ return {
state: { auth: null
auth: null }
}, }
mutations: { export const mutations = {
setAuth(state, auth) { setAuth(state, auth) {
state.auth = auth state.auth = auth
} }
}, }
actions: { export const actions = {
nuxtServerInit({ commit }, { req }) { nuxtServerInit({ commit }, { req }) {
let auth = null let auth = null
if (req.headers.cookie) { if (req.headers.cookie) {
const parsed = cookieparser.parse(req.headers.cookie) const parsed = cookieparser.parse(req.headers.cookie)
try { try {
auth = JSON.parse(parsed.auth) auth = JSON.parse(parsed.auth)
} catch (err) { } catch (err) {
// No valid cookie found // No valid cookie found
}
}
commit('setAuth', auth)
} }
} }
}) commit('setAuth', auth)
}
} }
export default createStore