mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-01 12:03:55 +01:00
Better login/logout actions
This commit is contained in:
@@ -2,4 +2,10 @@
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup></script>
|
||||
<script setup>
|
||||
import { useAuthStore } from '@/stores'
|
||||
|
||||
const authStore = useAuthStore()
|
||||
|
||||
authStore.initialize()
|
||||
</script>
|
||||
|
||||
@@ -313,7 +313,6 @@ function displayMenuItem(item) {
|
||||
|
||||
async function logout() {
|
||||
getActivePinia()._s.forEach(async (store) => await store.$reset())
|
||||
router.push({ name: 'Login' })
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -299,26 +299,18 @@ router.beforeEach((to, from, next) => {
|
||||
const previousPage = window.location.href
|
||||
sessionStorage.setItem('previousPage', previousPage)
|
||||
const authStore = useAuthStore()
|
||||
authStore.initialize().then((res) => {
|
||||
if (res === null) {
|
||||
next({name: 'Login'})
|
||||
authStore.validateAccess()
|
||||
if (to.meta.allowedRoles !== undefined) {
|
||||
if (to.meta.allowedRoles.indexOf(authStore.authUser.role) === -1) {
|
||||
next({ name: 'Dashboard' })
|
||||
return
|
||||
}
|
||||
authStore.validateAccess()
|
||||
if (to.meta.allowedRoles !== undefined) {
|
||||
if (to.meta.allowedRoles.indexOf(authStore.authUser.role) === -1) {
|
||||
next({ name: 'Dashboard' })
|
||||
return
|
||||
}
|
||||
}
|
||||
if (to.meta.requiresMailbox && !authStore.authUser.mailbox) {
|
||||
next({ name: 'Dashboard' })
|
||||
}
|
||||
next()
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
if (to.meta.requiresMailbox && !authStore.authUser.mailbox) {
|
||||
next({ name: 'Dashboard' })
|
||||
}
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
@@ -9,7 +9,6 @@ import { UserManager } from 'oidc-client-ts'
|
||||
import repository from '@/api/repository'
|
||||
import accountApi from '@/api/account'
|
||||
import accountsApi from '@/api/accounts'
|
||||
// import authApi from '@/api/auth'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const authUser = ref({})
|
||||
@@ -61,7 +60,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
async function login() {
|
||||
try {
|
||||
await manager.signinRedirect();
|
||||
await manager.signinRedirect()
|
||||
} catch (error) {
|
||||
console.error('Error logging in:', error)
|
||||
}
|
||||
@@ -71,13 +70,13 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
try {
|
||||
const user = await manager.signinRedirectCallback()
|
||||
isAuthenticated.value = true
|
||||
const previousPage = sessionStorage.getItem('previousPage');
|
||||
const previousPage = sessionStorage.getItem('previousPage')
|
||||
// Redirect the user to the previous page if available
|
||||
if (previousPage) {
|
||||
window.location.href = previousPage;
|
||||
window.location.href = previousPage
|
||||
} else {
|
||||
// Redirect to a default page if the previous page is not available
|
||||
router.push({name : 'Dashboard'});
|
||||
router.push({ name: 'Dashboard' })
|
||||
}
|
||||
return user
|
||||
} catch (error) {
|
||||
@@ -91,6 +90,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
authUser.value = {}
|
||||
isAuthenticated.value = false
|
||||
//TODO: Call the logout callback of OIDC and log out from the IdP
|
||||
manager.signoutRedirect()
|
||||
}
|
||||
|
||||
async function updateAccount(data) {
|
||||
|
||||
Reference in New Issue
Block a user