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

90
Views
set header in response

I haven't work with cookies before and currently trying to store data in cookies.This is the response I am getting in console.log()

response in console.log()

I want to set cookies in header with setHeader(). This is the async function getjwt() using to send data to backend.

async function getjwt(req, res) {
  const apiRes= await fetch(
    `${process.env.NEXT_PUBLIC_API_URL}/auth/jwt/create`,
    {
      method: "POST",
      headers: {
        Accept: "application/json",
        "content-Type": "application/json",
      },
      body: Body,
    }
  );
  console.log(apiRes);
  const data = await apiRes.json();
  console.log("+++++++++++++++++++++");
  console.log(data.access);
  console.log("+++++++++++++++++++++");
  if (apiRes.status === 200) {
    res.setHeader("Set-Cookie", [
      cookie.serialize("access", data.access, {
        httpOnly: true,
        secure: false,
        maxAge: 60 * 30,
        sameSite: "strict",
        path: "/auth/",
      }),
      cookie.serialize("refresh", data.refresh, {
        httpOnly: true,
        secure: false,
        maxAge: 60 * 60 * 24,
        sameSite: "strict",
        path: "/auth/",
      }),
    ]);
  } else {
    return res.status(apiRes.status).json({
      error: "Authentication failed",
    });
  }
}

ERROR-

Uncaught (in promise) TypeError: res is undefined

how can I set Header in response.

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!