79414871

Date: 2025-02-05 13:17:13
Score: 1
Natty:
Report link

Huge kudos to @JonathanLauxenRomano's answer.

Here's how I made it work in App Router (same idea, new router):

import { headers } from 'next/headers'

await fetch(`${process.env.NEXT_PUBLIC_BASE_PATH}/api/test`, {
    headers: {
      Cookie: headers().get('cookie') ?? ''
    }
  })

I tried using cookies, retrieving the exact cookie from nextauth and manually retrieving the token in the API route... But this way the await getToken({req}) just works as expected!

Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @JonathanLauxenRomano's
  • Low reputation (0.5):
Posted by: Nikolai