| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import VuexORM from '@vuex-orm/core'
- const cookieparser = process.server ? require('cookieparser') : undefined
- export const plugins = [
- VuexORM.install()
- ];
- export const actions = {
- /**
- * Méthode appelée lors de la phase d'initialisation de Nuxt coté serveur (SSR)
- * @param commit
- * @param dispatch
- * @param req
- * @return {Promise<void>}
- */
- async nuxtServerInit({dispatch}, {req}) {
- const initCookie = await dispatch('initCookies', {req: req})
- const updateProfile = await dispatch('updateProfile')
- },
- /**
- * Récupère et Store les Cookies Bearer et XAccessId
- * @param commit
- * @param req
- * @return {Promise<void>}
- */
- async initCookies({commit}, {req}){
- let bearer = null
- let accessId = null
- if (req.headers.cookie) {
- const parsed = cookieparser.parse(req.headers.cookie)
- try {
- bearer = parsed.BEARER
- } catch (err) {
- // No valid cookie found
- }
- try {
- accessId = parsed.AccessId
- } catch (err) {
- // No valid Access Id found
- }
- }
- commit('profile/access/setBearer', bearer)
- commit('profile/access/setAccessId', accessId)
- },
- /**
- * Récupère les informations du profile connecté et update le Store Profile
- * @param dispatch
- * @param state
- * @return {Promise<void>}
- */
- async updateProfile({dispatch, state}) {
- const my_profile = await this.$http.$get(`/api/my_profile/${state.profile.access.accessId}`)
- dispatch('profile/access/setProfile', my_profile)
- },
- }
|