mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-16 23:01:06 +02:00
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:
parent
0cd997f673
commit
baada1457a
3 changed files with 12 additions and 9 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { AnimatePresence, motion } from "motion/react";
|
import { AnimatePresence, motion } from "motion/react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
import { useSearchParams } from "next/navigation";
|
import { useSearchParams } from "next/navigation";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { Suspense, useEffect, useState } from "react";
|
import { Suspense, useEffect, useState } from "react";
|
||||||
|
|
@ -16,6 +17,7 @@ import { LocalLoginForm } from "./LocalLoginForm";
|
||||||
function LoginContent() {
|
function LoginContent() {
|
||||||
const t = useTranslations("auth");
|
const t = useTranslations("auth");
|
||||||
const tCommon = useTranslations("common");
|
const tCommon = useTranslations("common");
|
||||||
|
const router = useRouter();
|
||||||
const [authType, setAuthType] = useState<string | null>(null);
|
const [authType, setAuthType] = useState<string | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [urlError, setUrlError] = useState<{ title: string; message: string } | null>(null);
|
const [urlError, setUrlError] = useState<{ title: string; message: string } | null>(null);
|
||||||
|
|
@ -79,7 +81,7 @@ function LoginContent() {
|
||||||
if (shouldRetry(error)) {
|
if (shouldRetry(error)) {
|
||||||
toastOptions.action = {
|
toastOptions.action = {
|
||||||
label: "Retry",
|
label: "Retry",
|
||||||
onClick: () => window.location.reload(),
|
onClick: () => router.refresh(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import { BadgeCheck, LogOut } from "lucide-react";
|
import { BadgeCheck, LogOut } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
@ -27,6 +28,7 @@ export function UserDropdown({
|
||||||
avatar: string;
|
avatar: string;
|
||||||
};
|
};
|
||||||
}) {
|
}) {
|
||||||
|
const router = useRouter();
|
||||||
const [isLoggingOut, setIsLoggingOut] = useState(false);
|
const [isLoggingOut, setIsLoggingOut] = useState(false);
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
|
|
@ -40,16 +42,14 @@ export function UserDropdown({
|
||||||
// Revoke refresh token on server and clear all tokens from localStorage
|
// Revoke refresh token on server and clear all tokens from localStorage
|
||||||
await logout();
|
await logout();
|
||||||
|
|
||||||
if (typeof window !== "undefined") {
|
router.push("/");
|
||||||
window.location.href = "/";
|
router.refresh();
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error during logout:", error);
|
console.error("Error during logout:", error);
|
||||||
// Even if there's an error, try to clear tokens and redirect
|
// Even if there's an error, try to clear tokens and redirect
|
||||||
await logout();
|
await logout();
|
||||||
if (typeof window !== "undefined") {
|
router.push("/");
|
||||||
window.location.href = "/";
|
router.refresh();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
|
|
@ -43,6 +44,7 @@ interface CreateSearchSpaceDialogProps {
|
||||||
export function CreateSearchSpaceDialog({ open, onOpenChange }: CreateSearchSpaceDialogProps) {
|
export function CreateSearchSpaceDialog({ open, onOpenChange }: CreateSearchSpaceDialogProps) {
|
||||||
const t = useTranslations("searchSpace");
|
const t = useTranslations("searchSpace");
|
||||||
const tCommon = useTranslations("common");
|
const tCommon = useTranslations("common");
|
||||||
|
const router = useRouter();
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
const { mutateAsync: createSearchSpace } = useAtomValue(createSearchSpaceMutationAtom);
|
const { mutateAsync: createSearchSpace } = useAtomValue(createSearchSpaceMutationAtom);
|
||||||
|
|
@ -65,8 +67,7 @@ export function CreateSearchSpaceDialog({ open, onOpenChange }: CreateSearchSpac
|
||||||
|
|
||||||
trackSearchSpaceCreated(result.id, values.name);
|
trackSearchSpaceCreated(result.id, values.name);
|
||||||
|
|
||||||
// Hard redirect to ensure fresh state
|
router.push(`/dashboard/${result.id}/onboard`);
|
||||||
window.location.href = `/dashboard/${result.id}/onboard`;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to create search space:", error);
|
console.error("Failed to create search space:", error);
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue