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 = {
|
2019-07-10 10:45:49 +00:00
|
|
|
setAuth (state, auth) {
|
2019-05-21 17:56:37 +00:00
|
|
|
state.auth = auth
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export const actions = {
|
2019-07-10 10:45:49 +00:00
|
|
|
nuxtServerInit ({ commit }, { req }) {
|
2019-05-21 17:56:37 +00:00
|
|
|
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
|
|
|
}
|