Enable the Vue 3 front-end

This commit is contained in:
Bubka
2023-12-01 15:29:26 +01:00
parent ffde1723d4
commit 9efb54adf4
146 changed files with 2000 additions and 9387 deletions

View File

@ -0,0 +1,28 @@
import authService from '@/services/authService'
export default async function authGuard({ to, next, nextMiddleware, stores }) {
const { user } = stores
// No authenticated user on the front-end side, we try to
// get an active user from the back-end side
if (! user.isAuthenticated) {
await authService.getCurrentUser({ returnError: true }).then(async (response) => {
const currentUser = response.data
await user.loginAs({
name: currentUser.name,
email: currentUser.email,
preferences: currentUser.preferences,
isAdmin: currentUser.is_admin,
})
})
.catch(error => {
// nothing to do
})
}
if (! user.isAuthenticated) {
next({ name: 'login' })
} else {
nextMiddleware()
}
}