diff --git a/surfsense_web/app/(home)/login/page.tsx b/surfsense_web/app/(home)/login/page.tsx index 8b3be3805..b1380486f 100644 --- a/surfsense_web/app/(home)/login/page.tsx +++ b/surfsense_web/app/(home)/login/page.tsx @@ -1,13 +1,14 @@ "use client"; import { AnimatePresence, motion } from "motion/react"; -import { useSearchParams } from "next/navigation"; +import { useRouter, useSearchParams } from "next/navigation"; import { useTranslations } from "next-intl"; import { Suspense, useEffect, useState } from "react"; import { toast } from "sonner"; import { Logo } from "@/components/Logo"; import { useGlobalLoadingEffect } from "@/hooks/use-global-loading"; import { getAuthErrorDetails, shouldRetry } from "@/lib/auth-errors"; +import { getBearerToken } from "@/lib/auth-utils"; import { AUTH_TYPE } from "@/lib/env-config"; import { AmbientBackground } from "./AmbientBackground"; import { GoogleLoginButton } from "./GoogleLoginButton"; @@ -16,11 +17,19 @@ import { LocalLoginForm } from "./LocalLoginForm"; function LoginContent() { const t = useTranslations("auth"); const tCommon = useTranslations("common"); + const router = useRouter(); const [authType, setAuthType] = useState(null); const [isLoading, setIsLoading] = useState(true); const [urlError, setUrlError] = useState<{ title: string; message: string } | null>(null); const searchParams = useSearchParams(); + useEffect(() => { + if (getBearerToken()) { + router.replace("/dashboard"); + return; + } + }, [router]); + useEffect(() => { // Check for various URL parameters that might indicate success or error states const registered = searchParams.get("registered"); diff --git a/surfsense_web/app/(home)/page.tsx b/surfsense_web/app/(home)/page.tsx index 2c1a70ac9..e6f1231a3 100644 --- a/surfsense_web/app/(home)/page.tsx +++ b/surfsense_web/app/(home)/page.tsx @@ -1,6 +1,9 @@ "use client"; import dynamic from "next/dynamic"; +import { useRouter } from "next/navigation"; +import { useEffect } from "react"; +import { getBearerToken } from "@/lib/auth-utils"; import { HeroSection } from "@/components/homepage/hero-section"; const FeaturesCards = dynamic( @@ -26,6 +29,14 @@ const CTAHomepage = dynamic( ); export default function HomePage() { + const router = useRouter(); + + useEffect(() => { + if (getBearerToken()) { + router.replace("/dashboard"); + } + }, [router]); + return (
diff --git a/surfsense_web/app/(home)/register/page.tsx b/surfsense_web/app/(home)/register/page.tsx index 96fab2c6a..b9200c68f 100644 --- a/surfsense_web/app/(home)/register/page.tsx +++ b/surfsense_web/app/(home)/register/page.tsx @@ -11,6 +11,7 @@ import { registerMutationAtom } from "@/atoms/auth/auth-mutation.atoms"; import { Logo } from "@/components/Logo"; import { Spinner } from "@/components/ui/spinner"; import { getAuthErrorDetails, isNetworkError, shouldRetry } from "@/lib/auth-errors"; +import { getBearerToken } from "@/lib/auth-utils"; import { AUTH_TYPE } from "@/lib/env-config"; import { AppError, ValidationError } from "@/lib/error"; import { @@ -38,6 +39,10 @@ export default function RegisterPage() { // Check authentication type and redirect if not LOCAL useEffect(() => { + if (getBearerToken()) { + router.replace("/dashboard"); + return; + } if (AUTH_TYPE !== "LOCAL") { router.push("/login"); }