54 lines
1.5 KiB
TypeScript
54 lines
1.5 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')
|
|
}
|
|
|
|
// Ha foglalás oldalon vagyunk
|
|
if (to.fullPath.match(/^\/rent/gi)) {
|
|
// console.log(authStore.rent)
|
|
// if(!authStore.rent?.auto_felvetel_datum){
|
|
// return navigateTo('/rent/date-from')
|
|
// }
|
|
}
|
|
})
|