diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 536ff01ec..59773d207 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM python:3.12-alpine AS base +FROM python:3.12-alpine3.20 AS base LABEL org.opencontainers.image.authors="Antoine Nguyen " ENV VIRTUAL_ENV=/opt/venv diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index c5bb5076d..580a49303 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -280,15 +280,21 @@ router.beforeEach(async (to, from, next) => { if (!authStore.authUser) { await authStore.initialize() } - authStore.validateAccess() - if (to.meta.allowedRoles !== undefined) { - if (to.meta.allowedRoles.indexOf(authStore.authUser.role) === -1) { + const isAuth = await authStore.validateAccess() + if (isAuth) { + 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' }) return } - } - if (to.meta.requiresMailbox && !authStore.authUser.mailbox) { - next({ name: 'Dashboard' }) + } else { + next({ name: 'Login' }) + return } } next() diff --git a/frontend/src/stores/auth.store.js b/frontend/src/stores/auth.store.js index 0dab8cded..760c90574 100644 --- a/frontend/src/stores/auth.store.js +++ b/frontend/src/stores/auth.store.js @@ -115,11 +115,11 @@ export const useAuthStore = defineStore('auth', () => { async function validateAccess() { const user = await manager.getUser() if (!user || user.expired) { - manager.signinRedirect() - return + return false } repository.defaults.headers.common.Authorization = `Bearer ${user.access_token}` repository.defaults.headers.post['Content-Type'] = 'application/json' + return true } async function login() { @@ -145,6 +145,8 @@ export const useAuthStore = defineStore('auth', () => { return user } catch (error) { console.error('Error completing login:', error) + // Redirect to Dashboard so the router will attempt again login + router.push({ name: 'Dashboard' }) return null } } diff --git a/frontend/src/views/login/LoginCallbackView.vue b/frontend/src/views/login/LoginCallbackView.vue index 1ed9eb531..15610962c 100644 --- a/frontend/src/views/login/LoginCallbackView.vue +++ b/frontend/src/views/login/LoginCallbackView.vue @@ -9,4 +9,18 @@ onMounted(() => { diff --git a/frontend/src/views/login/LoginView.vue b/frontend/src/views/login/LoginView.vue index 042f797c5..76b93031d 100644 --- a/frontend/src/views/login/LoginView.vue +++ b/frontend/src/views/login/LoginView.vue @@ -13,8 +13,15 @@ onMounted(() => authStore.login())