keycloak.ts
669 Bytes
import { useKeycloakStore } from '@/@core/stores/keycloakStore'
import keycloakInstance from '@/keycloak'
export default defineNuxtPlugin(async nuxtApp => {
const keycloakStore = useKeycloakStore()
try {
const authenticated = await keycloakInstance.init({
onLoad: 'check-sso',
})
keycloakStore.authenticated = authenticated
if (authenticated) {
keycloakStore.refresh()
console.log('User is authenticated')
navigateTo('/naputpro/beranda/profile')
}
else {
console.log('User is not authenticated')
navigateTo('/login')
}
}
catch (error) {
console.error('Keycloak init error:', error)
}
})