Next.js Discord

Discord Forum

How to prevent full page reload?

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
I have a authentication button on the homepage which shows if the user is authenticated shows the sign out button otherwise sign in button.
For that I have created logic ex,

if (session.user) return <ProfileButton/> 
else return <SignIn/>


But the problem is when user sign out and navigate to the root page, still <ProfileButton/> shows. This problem solved if I set redirect to true. I don't want to do that.

<Button
      className="w-full"
      variant="default"
      type="button"
      onClick={async () => {
        const data = await signOut({
          redirect: false,
          callbackUrl: "/",
        })

        router.push(data.url)
      }}
    >
     Sign Out
 </Button>


In simple terms, On user sign out the only the <ProfileButton/> component reloads and show <SignIn/> Button.

Thanks.

0 Replies