fix(auth): redirect already-signed-in users away from the register page
CI/CD / CI · API (dotnet build + test) (push) Successful in 44s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 31s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m10s
CI/CD / CI · Admin Web (tsc) (push) Successful in 38s
CI/CD / CI · Website (tsc) (push) Successful in 45s
CI/CD / CI · Koja (tsc) (push) Successful in 51s
CI/CD / Deploy · all services (push) Successful in 2m55s
CI/CD / CI · API (dotnet build + test) (push) Successful in 44s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 31s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m10s
CI/CD / CI · Admin Web (tsc) (push) Successful in 38s
CI/CD / CI · Website (tsc) (push) Successful in 45s
CI/CD / CI · Koja (tsc) (push) Successful in 51s
CI/CD / Deploy · all services (push) Successful in 2m55s
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 (
|
||||
<div className="flex min-h-screen items-center justify-center bg-muted/30 p-4">
|
||||
<p className="text-sm text-muted-foreground">{t("redirecting")}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-muted/30 p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
|
||||
Reference in New Issue
Block a user