You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.0 KiB

  1. import { make } from 'vuex-pathify'
  2. import jwt from 'jsonwebtoken'
  3. import Cookies from 'js-cookie'
  4. const state = {
  5. id: 0,
  6. email: '',
  7. name: '',
  8. pictureUrl: '',
  9. localeCode: '',
  10. defaultEditor: '',
  11. permissions: [],
  12. iat: 0,
  13. exp: 0,
  14. authenticated: false
  15. }
  16. export default {
  17. namespaced: true,
  18. state,
  19. mutations: {
  20. ...make.mutations(state),
  21. REFRESH_AUTH(state) {
  22. const jwtCookie = Cookies.get('jwt')
  23. if (jwtCookie) {
  24. try {
  25. const jwtData = jwt.decode(jwtCookie)
  26. state.id = jwtData.id
  27. state.email = jwtData.email
  28. state.name = jwtData.name
  29. state.pictureUrl = jwtData.pictureUrl
  30. state.localeCode = jwtData.localeCode
  31. state.defaultEditor = jwtData.defaultEditor
  32. state.permissions = jwtData.permissions
  33. state.iat = jwtData.iat
  34. state.exp = jwtData.exp
  35. state.authenticated = true
  36. } catch (err) {
  37. console.debug('Invalid JWT. Silent authentication skipped.')
  38. }
  39. }
  40. }
  41. }
  42. }