From 286beccd41d3ae605d30a492e8a16e3934d5e2e9 Mon Sep 17 00:00:00 2001 From: Stef Lewandowski Date: Tue, 8 Oct 2024 18:01:24 +0100 Subject: [PATCH] fix: hook error on sign-in page --- .../src/app/sign-in/[[...sign-in]]/page.tsx | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/nextjs/src/app/sign-in/[[...sign-in]]/page.tsx b/apps/nextjs/src/app/sign-in/[[...sign-in]]/page.tsx index 05389f4dc..1fec6cab2 100644 --- a/apps/nextjs/src/app/sign-in/[[...sign-in]]/page.tsx +++ b/apps/nextjs/src/app/sign-in/[[...sign-in]]/page.tsx @@ -1,4 +1,9 @@ -import { SignIn } from "@clerk/nextjs"; +"use client"; + +import { useEffect } from "react"; + +import { SignIn, SignedIn, SignedOut, useUser } from "@clerk/nextjs"; +import { useRouter } from "next/navigation"; import SignUpSignInLayout from "@/components/SignUpSignInLayout"; @@ -8,7 +13,12 @@ const SignInPage = () => { return ( <> - + + + + + + @@ -16,4 +26,15 @@ const SignInPage = () => { ); }; +const RedirectToHome = () => { + const { user, isLoaded } = useUser(); + const router = useRouter(); + useEffect(() => { + if (user && isLoaded) { + router.push("/"); + } + }, [router, user, isLoaded]); + return null; +}; + export default SignInPage;