From e97752735c360ec70dd661936677d05e1311bdde Mon Sep 17 00:00:00 2001 From: wowo-zZ Date: Sat, 14 Mar 2026 15:31:12 +0800 Subject: [PATCH] fix(auth): improve logout flow to always redirect to home - Use window.location.href for full page refresh - Move redirect to finally block to ensure it always executes - Fix V7 migration to be a no-op since column is already jsonb --- .../migration/V7__fix_audit_log_jsonb_type.sql | 16 +++++++--------- web/src/shared/components/user-menu.tsx | 9 +++++---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/server/skillhub-app/src/main/resources/db/migration/V7__fix_audit_log_jsonb_type.sql b/server/skillhub-app/src/main/resources/db/migration/V7__fix_audit_log_jsonb_type.sql index becd1661..10fb3517 100644 --- a/server/skillhub-app/src/main/resources/db/migration/V7__fix_audit_log_jsonb_type.sql +++ b/server/skillhub-app/src/main/resources/db/migration/V7__fix_audit_log_jsonb_type.sql @@ -1,12 +1,10 @@ -- Fix audit_log detail_json column to properly handle JSONB type -- This migration ensures existing data is compatible with the JSONB type --- The column is already defined as jsonb in V1, but we need to ensure --- any existing string data can be properly cast to jsonb -ALTER TABLE audit_log -ALTER COLUMN detail_json TYPE jsonb -USING CASE - WHEN detail_json IS NULL THEN NULL - WHEN detail_json = '' THEN NULL - ELSE detail_json::jsonb -END; +-- The column is already defined as jsonb in V1, so this migration is a no-op +-- for fresh installations. For existing installations with text data, this would +-- have been needed, but since the column was always jsonb, we just verify it exists. + +-- No-op migration: column is already jsonb in V1 +-- This file exists to maintain migration version continuity +SELECT 1; diff --git a/web/src/shared/components/user-menu.tsx b/web/src/shared/components/user-menu.tsx index 9ad5f534..55978922 100644 --- a/web/src/shared/components/user-menu.tsx +++ b/web/src/shared/components/user-menu.tsx @@ -1,5 +1,5 @@ import { useTranslation } from 'react-i18next' -import { Link, useNavigate } from '@tanstack/react-router' +import { Link } from '@tanstack/react-router' import { useQueryClient } from '@tanstack/react-query' import { authApi } from '@/api/client' import { @@ -22,7 +22,6 @@ interface UserMenuProps { export function UserMenu({ user }: UserMenuProps) { const { t } = useTranslation() - const navigate = useNavigate() const queryClient = useQueryClient() const hasRole = (role: string) => user.platformRoles?.includes(role) ?? false @@ -34,10 +33,12 @@ export function UserMenu({ user }: UserMenuProps) { const handleLogout = async () => { try { await authApi.logout() - queryClient.setQueryData(['auth', 'me'], null) - navigate({ to: '/' }) } catch (error) { console.error('Logout failed:', error) + } finally { + // Always clear cache and redirect, even if API call fails + queryClient.setQueryData(['auth', 'me'], null) + window.location.href = '/' } }