fix: replace window.location with Next.js router for client-side navigation

- Replace window.location.href with router.push() + router.refresh() in UserDropdown logout
- Replace window.location.href with router.push() in CreateSearchSpaceDialog
- Replace window.location.reload() with router.refresh() in login page retry action
- Prevents full page reloads and preserves React state during in-app navigation
This commit is contained in:
SohamBhattacharjee2003 2026-04-08 04:28:41 +05:30
parent 0cd997f673
commit baada1457a
3 changed files with 12 additions and 9 deletions

View file

@ -2,6 +2,7 @@
import { BadgeCheck, LogOut } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
@ -27,6 +28,7 @@ export function UserDropdown({
avatar: string;
};
}) {
const router = useRouter();
const [isLoggingOut, setIsLoggingOut] = useState(false);
const handleLogout = async () => {
@ -40,16 +42,14 @@ export function UserDropdown({
// Revoke refresh token on server and clear all tokens from localStorage
await logout();
if (typeof window !== "undefined") {
window.location.href = "/";
}
router.push("/");
router.refresh();
} catch (error) {
console.error("Error during logout:", error);
// Even if there's an error, try to clear tokens and redirect
await logout();
if (typeof window !== "undefined") {
window.location.href = "/";
}
router.push("/");
router.refresh();
}
};