nuxt-start/middleware/01-profile.global.ts
2025-12-23 19:51:09 +01:00

46 lines
1.2 KiB
TypeScript

export default defineNuxtRouteMiddleware(async (to, from) => {
const authStore = useAuthStore()
// Csak bejelentkezett felhasználóknál ellenőrzünk
if (!authStore.user) {
return
}
// Ha már a profil oldalon vagyunk, ne irányítsunk át (végtelen loop elkerülése)
if (to.fullPath.match(/^\/profile/gi)) {
return
}
// Login és page oldalak kihagyása
if (to.fullPath.match(/^\/login/gi) || to.fullPath.match(/^\/page/gi)) {
return
}
// Kötelező mezők listája
const requiredFields = [
'nev',
'email',
'telefon',
'anyja_neve',
'szuletesi_hely',
'szuletesi_ido',
'nemzetiseg',
'szigszam',
'jogositvany_szama',
'lakcim'
] as const
const user = authStore.user as Record<string, any>
// Ellenőrizzük, hogy minden kötelező mező ki van-e töltve
const missingFields = requiredFields.filter(field => {
const value = user[field]
return !value || (typeof value === 'string' && value.trim() === '')
})
// Ha van hiányzó mező, átirányítjuk a profil oldalra
if (missingFields.length > 0) {
return navigateTo('/profile')
}
})