index.js 942 B

123456789101112131415161718192021222324252627282930313233343536
  1. import VuexORM from '@vuex-orm/core'
  2. const cookieparser = process.server ? require('cookieparser') : undefined
  3. export const plugins = [
  4. VuexORM.install()
  5. ];
  6. export const actions = {
  7. async nuxtServerInit({commit, dispatch}, {req}) {
  8. let bearer = null
  9. let accessId = null
  10. if (req.headers.cookie) {
  11. const parsed = cookieparser.parse(req.headers.cookie)
  12. try {
  13. bearer = parsed.BEARER
  14. } catch (err) {
  15. // No valid cookie found
  16. }
  17. try {
  18. accessId = parsed.AccessId
  19. } catch (err) {
  20. // No valid Access Id found
  21. }
  22. }
  23. commit('profile/access/setBearer', bearer)
  24. commit('profile/access/setAccessId', accessId)
  25. await dispatch('updateProfile')
  26. },
  27. async updateProfile({dispatch, state}) {
  28. const my_profile = await this.$http.$get(`/api/my_profile/${state.profile.access.accessId}`)
  29. dispatch('profile/access/setProfile', my_profile)
  30. },
  31. }