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
1020 B

  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(st) {
  22. const jwtCookie = Cookies.get('jwt')
  23. if (jwtCookie) {
  24. try {
  25. const jwtData = jwt.decode(jwtCookie)
  26. st.id = jwtData.id
  27. st.email = jwtData.email
  28. st.name = jwtData.name
  29. st.pictureUrl = jwtData.pictureUrl
  30. st.localeCode = jwtData.localeCode
  31. st.defaultEditor = jwtData.defaultEditor
  32. st.permissions = jwtData.permissions
  33. st.iat = jwtData.iat
  34. st.exp = jwtData.exp
  35. st.authenticated = true
  36. } catch (err) {
  37. console.debug('Invalid JWT. Silent authentication skipped.')
  38. }
  39. }
  40. }
  41. }
  42. }