Next.js Discord

Discord Forum

Server Component not refreshing

Californian posted this in #help-forum
Open in Discord
My code:

export default async function DashboardPage() {
    const session  = await getServerSession()

  return (
      {session ? (
        <DashboardModal />
      ) : (
          <p >
            Sign in to see this page

but the dashboard is not showing after signing in with sign in modal. I guess server component is not refreshing with new data? How can I fix this, because the usession hook works fine but I want to get into habit of using server components

4 Replies

This server code isn't tracking any state so it'd have to be re-rendered. Given the fact that it's a DashboardModal, it sounds like this should be a client component. Being a client component, you'd check for a session, if there isn't a session you display "Sign in to see this...". If there is a session you make an API request to the backend for the data needed to hydrate the DashboardModal
I'm pretty new to NextJS but this is how I understand Server components versus Client components
Japanese flying squid
is ur session null?
We need to run router.refresh() after logging in to fix. But the server component version seems to render the modal slower than client version after logging in.