mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 06:35:10 +00:00
e7cc2757c3
Co-authored-by: Alexander Lichter <manniL@gmx.net>
27 lines
547 B
JavaScript
27 lines
547 B
JavaScript
const cookieparser = process.server ? require('cookieparser') : undefined
|
|
|
|
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)
|
|
}
|
|
}
|