test new guard router

This commit is contained in:
Andreani Jean
2023-07-04 09:27:32 +02:00
parent a31d076721
commit e2a67eba90

View File

@@ -59,19 +59,27 @@ router.beforeEach(async (to, from, next) => {
to.name === 'my-settings' ||
to.name === 'my-sequences' ||
to.name === 'sequence'
const url = `${location.protocol}//${location.host}`
const nextRoute = `${url}${to.path}`
console.log(url)
console.log(nextRoute)
if (loggedRoutes) {
try {
const loginUrl = `/api/users/me`
const isKeycloakLogout = await axios.get(loginUrl)
const isSiteLogin = !!cookies.get('user_id')
if (isKeycloakLogout.status >= 300 || !isSiteLogin) {
window.location.replace(getAuthRoute('/auth/login', to.path))
window.location.replace(
`${url}auth/login?next_url=${encodeURIComponent(nextRoute)}`
)
} else {
next()
}
} catch (e) {
window.location.replace(getAuthRoute('/auth/login', to.path))
next()
console.log('CAAAATCH', `${url}/api/auth/login`)
window.location.replace(
`${url}/api/auth/login?next_url=${encodeURIComponent(nextRoute)}`
)
}
} else next()
})