mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-09 21:57:47 +02:00
Set up Store, Service & Routing to handle the sign in process
This commit is contained in:
50
resources/js_vue3/stores/user.js
vendored
50
resources/js_vue3/stores/user.js
vendored
@ -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 } })
|
||||
}
|
||||
// },
|
||||
}
|
||||
|
||||
},
|
||||
})
|
||||
|
Reference in New Issue
Block a user