diff --git a/examples/auth-jwt/store/index.js b/examples/auth-jwt/store/index.js index 8754193c40..b37ced1dac 100644 --- a/examples/auth-jwt/store/index.js +++ b/examples/auth-jwt/store/index.js @@ -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