From 6d71770f2e0b913ce2888d9b9eb7e9d90c2fc60c Mon Sep 17 00:00:00 2001 From: "soroush.asadi" Date: Sun, 21 Jun 2026 11:11:10 +0330 Subject: [PATCH] fix(auth): redirect already-signed-in users away from the register page Mirrors the login guard: visiting /register while authenticated redirects to the dashboard home (/) instead of showing the form. Gated on _hasHydrated; shows a brief redirecting state. Reuses the existing auth.redirecting string. Co-Authored-By: Claude Opus 4.8 --- .../src/app/[locale]/register/page.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/web/dashboard/src/app/[locale]/register/page.tsx b/web/dashboard/src/app/[locale]/register/page.tsx index 0521061..f375dac 100644 --- a/web/dashboard/src/app/[locale]/register/page.tsx +++ b/web/dashboard/src/app/[locale]/register/page.tsx @@ -58,8 +58,17 @@ function RegisterForm() { const t = useTranslations("auth"); const router = useRouter(); const setAuth = useAuthStore((s) => s.setAuth); + const user = useAuthStore((s) => s.user); + const hasHydrated = useAuthStore((s) => s._hasHydrated); const searchParams = useSearchParams(); + // Already signed in? Don't show the register form — send them into the app. + // Gate on _hasHydrated so a not-yet-rehydrated (null) session isn't misread. + const alreadyAuthed = hasHydrated && !!user?.accessToken; + useEffect(() => { + if (alreadyAuthed) router.replace("/"); + }, [alreadyAuthed, router]); + const [phone, setPhone] = useState(searchParams.get("phone") ?? ""); const [cafeName, setCafeName] = useState(""); const [slug, setSlug] = useState(""); @@ -123,6 +132,14 @@ function RegisterForm() { } }; + if (alreadyAuthed) { + return ( +
+

{t("redirecting")}

+
+ ); + } + return (