Fix SSR and defensive coding for Keycloak integration

- Add proper SSR guards and error handling
- Make authentication middleware more defensive
- Add null checks in useUnifiedAuth composable
- Prevent JavaScript errors from breaking page load
- Prioritize Directus auth over Keycloak for stability
This commit is contained in:
2025-06-14 15:01:45 +02:00
parent a797c13867
commit 8c7bf4cc00
3 changed files with 48 additions and 31 deletions

View File

@@ -9,7 +9,7 @@ export const useKeycloak = () => {
const isInitialized = ref(false)
const initKeycloak = async () => {
if (process.server) return
if (process.server) return false
try {
// Dynamically import keycloak-js

View File

@@ -15,8 +15,8 @@ export const useUnifiedAuth = () => {
// Create unified user object
const user = computed<UnifiedUser | null>(() => {
// Check Keycloak user first
if (keycloak.user.value) {
// Check Keycloak user first (safely)
if (keycloak.user?.value) {
const keycloakUser = keycloak.user.value;
// Construct name from firstName and lastName if available
let name = keycloakUser.name;