Skip to content

Unable to retrieve access token for client side call to non-next.js backend #2130

Open
@SarmanAulakh

Description

@SarmanAulakh

Checklist

Description

Using Page Router in Next.js 14, I've implement auth for login/signup. I'm also able to get the access token on the server side/middleware of next.js.

I'm trying to get the access token and make a request to my Go backend without using a Next.js api endpoint as a proxy (which works, but is a lot of boilerplate to make an additional next.js endpoint just to then call my go endpoint).

https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#getting-an-access-token

I've tried using import { getAccessToken } from "@auth0/nextjs-auth0" as shown in the docs, but I believe its for App Router only. When using it on page router, i get 'cookies was called outside a request scope'

Image

Image

Reproduction

  1. Setup next.js 14 page router
  2. setup auth/login using nextjs-auth
  3. try to make a call to an external api (ex. Golang backend) without using next.js api router as a proxy, for example in a useEffect or using useSWR

Additional context

No response

nextjs-auth0 version

^3.5.0

Next.js version

^14.2.5 Page Router

Node.js version

18.17.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions