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

136
Views
Next.js and Next Auth and fetch

So I am trying to develop the next app with a protected API route. When is simply use browser to call the API it response the output but when I use from client call It return null,

Output when I do call from browser

Console Log Output

But when I do from client-side it returns null

Client Side console

Next Js client side

export async function getServerSideProps() {
const res = await fetch(`${host}/api/categories`);
const categories: DataC = await res.json();

const resS = await fetch(`${host}/api/subcategories`);
const subcategories: DataS = await resS.json();


const resProducts = await fetch(`${host}/api/addproducts`,);
const products: productRes = await resProducts.json();

return (.....)
}

Next JS Api part

import type { NextApiRequest, NextApiResponse } from 'next'
import { Category, PrismaClient, Subcategory } from '@prisma/client'
import { getSession } from 'next-auth/react';

export default async function handler(
    req: NextApiRequest,
    res: NextApiResponse<Data>
) {
    try {
        const session = await getSession({ req });
        console.log(session);
        .......
     }catch (error) {
        console.log(error);
        res.status(500).json({ success: false, product: null });
    }
}

I Have also tried with credentials: 'include', credentials: 'same-site' but it didn't work

EDIT:

[https://stackoverflow.com/questions/69057271/why-are-cookies-not-sent-to-the-server-via-getserversideprops-in-next-js][4]

Here is the solution

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!