index.js 917 B

12345678910111213141516171819202122232425262728293031323334353637
  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 cookie found
  21. }
  22. }
  23. commit('myProfile/setBearer', bearer)
  24. commit('myProfile/setAccessId', accessId)
  25. await dispatch('updateProfile')
  26. },
  27. async updateProfile({ commit, state }) {
  28. const my_profile = await this.$http.$get(`/api/my_profile/${state.myProfile.accessId}`)
  29. commit('myProfile/setProfile', my_profile)
  30. },
  31. }