Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
Nex js: Should next js server deal with user specific data?

I am currently learning about next js and I have a few questions in mind. These are not real projects I am working on but just examples.

Let's say I have my frontend app running on 'example.com' and an api server 'api.example.com'. The api is using normal session-cookie authentication for the spa.

I have a page called pages/projects which shows the user's current project, now for ssr should the server just pre-render a loading state of the page and let the client fetch the data from the api? Or should I use the user cookies and query the api during ssr in order to load the completed version of the page?

const Page: NextPage<Props> = ({ projects }: Props) => {
  return(
    <>
      {projects.map((project) => {
        // render out ProjectItem component.
      })}
    </>
  )
}

Page.getInitialProps = async (context) => {
  if (context.req) {
    // fetch data using the user's cookies
  } else {
    // fetch data on client side 
  }
  // the part above could be abstracted to be reused.
  return {
    projects: result.data
  }
}

export default Page

Or stick to useEffect and just pre render a loading page? This only concerns the first page load, as navigating to it through next/link will make the client directly contact the api so is that the right thing to do also in the first load? Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!