Skip to content

Commit

Permalink
Merge pull request #3386 from modoboa/qol/display-loading-on-loading
Browse files Browse the repository at this point in the history
Display text when login on new-admin
  • Loading branch information
mergify[bot] authored Dec 20, 2024
2 parents 97e2cf2 + 52c31a2 commit 049b24f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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 <tonio@ngyn.org>"
ENV VIRTUAL_ENV=/opt/venv
Expand Down
18 changes: 12 additions & 6 deletions frontend/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/stores/auth.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
}
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/views/login/LoginCallbackView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ onMounted(() => {
</script>

<template>
<v-container class="fill-height" fluid>
<v-row align="center" justify="center">
<v-col cols="auto" class="text-center">
<h1 class="ma-5">{{ $gettext('Attempting to log you in.') }}</h1>
<v-progress-circular
color="primary"
indeterminate
:size="128"
:width="12"
align-self="center"
></v-progress-circular>
</v-col>
</v-row>
</v-container>
</template>
11 changes: 9 additions & 2 deletions frontend/src/views/login/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ onMounted(() => authStore.login())
<template>
<v-container class="fill-height" fluid>
<v-row align="center" justify="center">
<v-col>
<h1>{{ $gettext('Attempting to log you in.') }}</h1>
<v-col cols="auto" class="text-center">
<h1 class="ma-5">{{ $gettext('Attempting to log you in.') }}</h1>
<v-progress-circular
color="primary"
indeterminate
:size="128"
:width="12"
align-self="center"
></v-progress-circular>
</v-col>
</v-row>
</v-container>
Expand Down

0 comments on commit 049b24f

Please sign in to comment.