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

184
Views
How to get cookies in _app.js in next js

I want to get cookies in _app.js in next js but I cant and it always return undefined is there a way to solve this problem also a lot of people are saying you should use getInitialProps but in the documentation, it says it is not recommended

here is my _app.js

import "tailwindcss/tailwind.css";
import Navbar from "../components/Navbar.js"

function MyApp({ Component, pageProps, token }) {
  return (
   <Navbar token={token} />
   <Component {...pageProps} />;
  )
}

export default MyApp;

export const getServerSideProps = ({ req, res }) => {
  return {
    props: {
      token: req.cookies.token,
    },
  };
};

I am trying to access the navbar in _app.js and get the cookie token but it always returns undefined but when I do it elsewhere like index.js it works completely fine

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!