Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #52 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
28 lines
782 B
TypeScript
28 lines
782 B
TypeScript
import { useAuthStore } from '~/stores/auth'
|
|
|
|
/**
|
|
* Garde-fou global : empêche les utilisateurs non-admin d'accéder aux pages
|
|
* sous /admin/*. Renvoie vers la home pour les utilisateurs authentifiés
|
|
* non-admin, et vers /login pour les non authentifiés.
|
|
*
|
|
* L'API back rejette de toute façon les actions admin avec un 403, mais ce
|
|
* middleware évite l'affichage des pages vides / en erreur quand un user
|
|
* tape directement l'URL /admin/...
|
|
*/
|
|
export default defineNuxtRouteMiddleware(async (to) => {
|
|
if (!to.path.startsWith('/admin')) {
|
|
return
|
|
}
|
|
|
|
const auth = useAuthStore()
|
|
await auth.ensureSession()
|
|
|
|
if (!auth.isAuthenticated) {
|
|
return navigateTo('/login')
|
|
}
|
|
|
|
if (!auth.isAdmin) {
|
|
return navigateTo('/')
|
|
}
|
|
})
|