From d272e05d7e4392c5e58ea1d1b38230a7c97ef73d Mon Sep 17 00:00:00 2001 From: "Yeyang (Justin) Sun" Date: Tue, 20 Feb 2024 02:43:18 +1030 Subject: [PATCH] feat: refresh rsc after mutation (#94) --- src/app/(account)/join/steps/StepFour.tsx | 1 + src/app/(account)/join/steps/StepOne.tsx | 3 +++ src/app/(account)/signin/page.tsx | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/app/(account)/join/steps/StepFour.tsx b/src/app/(account)/join/steps/StepFour.tsx index 8f74defa..a32dc9ff 100644 --- a/src/app/(account)/join/steps/StepFour.tsx +++ b/src/app/(account)/join/steps/StepFour.tsx @@ -26,6 +26,7 @@ export default function StepFour() { }, onSuccess: () => { router.push('/settings'); + router.refresh(); }, }); diff --git a/src/app/(account)/join/steps/StepOne.tsx b/src/app/(account)/join/steps/StepOne.tsx index 9d13d0fe..d4a710fd 100644 --- a/src/app/(account)/join/steps/StepOne.tsx +++ b/src/app/(account)/join/steps/StepOne.tsx @@ -3,6 +3,7 @@ import ControlledField from '@/components/ControlledField'; import { useSignUp } from '@clerk/nextjs'; import { zodResolver } from '@hookform/resolvers/zod'; import Link from 'next/link'; +import { useRouter } from 'next/navigation'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { FcGoogle } from 'react-icons/fc'; @@ -33,6 +34,7 @@ function VerifyEmail() { const [verifyEmailLoading, setVerifyEmailLoading] = useState(false); + const router = useRouter(); const handleVerify = form.handleSubmit(async ({ code }) => { if (!isLoaded) return; @@ -48,6 +50,7 @@ function VerifyEmail() { return; } await setActive({ session: completeSignUp.createdSessionId }); + router.refresh(); } catch (error) { handleClerkErrors(error, form, [ { code: 'form_param_nil', field: 'code', message: 'Please enter the the code.' }, diff --git a/src/app/(account)/signin/page.tsx b/src/app/(account)/signin/page.tsx index cfe5d786..18acf891 100644 --- a/src/app/(account)/signin/page.tsx +++ b/src/app/(account)/signin/page.tsx @@ -6,6 +6,7 @@ import FancyRectangle from '@/components/FancyRectangle'; import { useSignIn } from '@clerk/clerk-react'; import { zodResolver } from '@hookform/resolvers/zod'; import Link from 'next/link'; +import { useRouter } from 'next/navigation'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { FcGoogle } from 'react-icons/fc'; @@ -28,6 +29,7 @@ export default function SignInPage() { const [signInLoading, setSignInLoading] = useState(false); + const router = useRouter(); const handleSignIn = form.handleSubmit(async ({ email, password }) => { if (!isLoaded) return; @@ -41,7 +43,8 @@ export default function SignInPage() { if (result.status === 'complete') { await setActive({ session: result.createdSessionId }); - location.href = '/'; + router.push('/'); + router.refresh(); } else { console.log(result); }