2023-09-22 15:07:47 +02:00
|
|
|
import { defineStore } from 'pinia'
|
2023-09-27 10:44:54 +02:00
|
|
|
import authService from '@/services/authService'
|
|
|
|
import router from '@/router'
|
2023-09-22 15:07:47 +02:00
|
|
|
|
|
|
|
export const useUserStore = defineStore({
|
2023-09-27 10:44:54 +02:00
|
|
|
id: 'user',
|
2023-09-22 15:07:47 +02:00
|
|
|
|
2023-09-27 10:44:54 +02:00
|
|
|
state: () => {
|
2023-09-22 15:07:47 +02:00
|
|
|
return {
|
2023-09-27 10:44:54 +02:00
|
|
|
name: undefined,
|
|
|
|
preferences: window.defaultPreferences,
|
2023-09-22 15:07:47 +02:00
|
|
|
isAdmin: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-09-27 10:44:54 +02:00
|
|
|
getters: {
|
|
|
|
isAuthenticated() {
|
|
|
|
return this.name != undefined
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
updatePreference(preference) {
|
|
|
|
this.preferences = { ...this.state.preferences, ...preference }
|
|
|
|
},
|
|
|
|
|
|
|
|
logout() {
|
|
|
|
// async appLogout(evt) {
|
|
|
|
if (this.$2fauth.config.proxyAuth) {
|
|
|
|
if (this.$2fauth.config.proxyLogoutUrl) {
|
|
|
|
location.assign(this.$2fauth.config.proxyLogoutUrl)
|
|
|
|
}
|
|
|
|
else return false
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return authService.logout().then(() => {
|
2023-09-28 13:23:58 +02:00
|
|
|
this.reset()
|
2023-09-27 10:44:54 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// this.$router.push({ name: 'login', params: { forceRefresh: true } })
|
|
|
|
}
|
|
|
|
// },
|
2023-09-28 13:23:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
localStorage.clear()
|
|
|
|
this.$reset()
|
|
|
|
router.push({ name: 'login' })
|
2023-09-27 10:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2023-09-22 15:07:47 +02:00
|
|
|
})
|