2018-08-17 05:49:06 +00:00
|
|
|
const cookieparser = process.server ? require('cookieparser') : undefined
|
|
|
|
|
2019-05-21 17:56:37 +00:00
|
|
|
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
|
2018-08-17 05:49:06 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-21 17:56:37 +00:00
|
|
|
commit('setAuth', auth)
|
|
|
|
}
|
2018-08-17 05:49:06 +00:00
|
|
|
}
|