user.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { defineStore } from 'pinia'
  2. import authService from '@/services/authService'
  3. import router from '@/router'
  4. export const useUserStore = defineStore({
  5. id: 'user',
  6. state: () => {
  7. return {
  8. name: undefined,
  9. preferences: window.defaultPreferences,
  10. isAdmin: false,
  11. }
  12. },
  13. getters: {
  14. isAuthenticated() {
  15. return this.name != undefined
  16. }
  17. },
  18. actions: {
  19. updatePreference(preference) {
  20. this.preferences = { ...this.state.preferences, ...preference }
  21. },
  22. logout() {
  23. // async appLogout(evt) {
  24. if (this.$2fauth.config.proxyAuth) {
  25. if (this.$2fauth.config.proxyLogoutUrl) {
  26. location.assign(this.$2fauth.config.proxyLogoutUrl)
  27. }
  28. else return false
  29. }
  30. else {
  31. return authService.logout().then(() => {
  32. localStorage.clear()
  33. this.$reset()
  34. router.push({ name: 'login' })
  35. })
  36. // this.$router.push({ name: 'login', params: { forceRefresh: true } })
  37. }
  38. // },
  39. }
  40. },
  41. })