2FAuth/resources/js_vue3/stores/user.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-09-22 15:07:47 +02:00
import { defineStore } from 'pinia'
import authService from '@/services/authService'
import router from '@/router'
2023-09-22 15:07:47 +02:00
export const useUserStore = defineStore({
id: 'user',
2023-09-22 15:07:47 +02:00
state: () => {
2023-09-22 15:07:47 +02:00
return {
name: undefined,
preferences: window.defaultPreferences,
2023-09-22 15:07:47 +02:00
isAdmin: false,
}
},
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(() => {
this.reset()
})
// this.$router.push({ name: 'login', params: { forceRefresh: true } })
}
// },
},
reset() {
localStorage.clear()
this.$reset()
router.push({ name: 'login' })
}
},
2023-09-22 15:07:47 +02:00
})