23 lines
620 B
TypeScript
23 lines
620 B
TypeScript
import { useKeycloak } from "~/composables/useKeycloack"
|
|
|
|
export default defineNuxtRouteMiddleware(async (to) => {
|
|
if (to.meta.public) return
|
|
// if (!to.meta?.requiresAuth) return;
|
|
|
|
const { $pinia } = useNuxtApp()
|
|
|
|
const { initKeycloak, isAuthenticated, getResponse} = useKeycloak(); // global composable
|
|
await initKeycloak("check-sso");
|
|
|
|
if (import.meta.client) {
|
|
const userStore = useUserStore($pinia)
|
|
if (!userStore.isAuthenticated && !isAuthenticated.value) {
|
|
return navigateTo('/auth/login')
|
|
} else {
|
|
if (isAuthenticated.value) {
|
|
await getResponse()
|
|
}
|
|
}
|
|
}
|
|
})
|