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:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user