Set up Store, Service & Routing to handle the sign in process

This commit is contained in:
Bubka
2023-09-27 10:44:54 +02:00
parent 1d51cb3e31
commit 48bea5721f
10 changed files with 685 additions and 46 deletions

View File

@ -1,22 +1,48 @@
import { defineStore } from 'pinia'
// import { useApi } from '@/api/useAPI.js'
// const api = useApi()
import authService from '@/services/authService'
import router from '@/router'
export const useUserStore = defineStore({
id: 'user',
id: 'user',
state: () => {
state: () => {
return {
name: 'guest',
preferences: window.userPreferences,
name: undefined,
preferences: window.defaultPreferences,
isAdmin: false,
}
},
actions: {
updatePreference(preference) {
this.preferences = { ...this.state.preferences, ...preference }
},
},
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(() => {
localStorage.clear()
this.$reset()
router.push({ name: 'login' })
})
// this.$router.push({ name: 'login', params: { forceRefresh: true } })
}
// },
}
},
})