Skip to content

Sample application does not copy cookie headers from Auth0 response to Intl response correctly #2340

@bonbor

Description

@bonbor

Checklist

Description

In the example for how to setup nextjs-auth0 with intl, there is a middleware file that show how to copy header values form Auth0 response to intl response. The code line that writes header values to intl response looks like this: intlRes.headers.set(key, value);. If the header value exists, the previous value will be overwritten. The Auth0 response contains multiple set-cookie headers. Since headers.set is used in stead of headers.append, only the last cookie is written to the response. Because of this error, the session is not updated correctly and it will expire before its absolute expiry time even though the user is actively using the application. Can we update the example so that it uses append?

Also, I think it is a common use case to have other middleware that generates responses. Could the SDK be extended with a helper method for copying the header values?

Reproduction

.

Additional context

Example logging of headers that are copied from Auth0 response to intl response:

Copying cookie from auth response. "cache-control"="private, no-cache, no-sto..."
Copying cookie from auth response. "expires"="0..."
Copying cookie from auth response. "pragma"="no-cache..."
Copying cookie from auth response. "set-cookie"="__session__0=eyJlbmMiOiJB..."
Copying cookie from auth response. "set-cookie"="__session__1=rgPjj5rbkWdW..."
Copying cookie from auth response. "set-cookie"="__session=; Path=/; Max-A..."
Copying cookie from auth response. "set-cookie"="appSession=; Path=/; Max-..."
Copying cookie from auth response. "x-middleware-next"="1..."
Copying cookie from auth response. "x-middleware-set-cookie"="__session__0=eyJlbmMiOiJB..."

nextjs-auth0 version

4.10.0

Next.js version

15.5.3

Node.js version

22.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    ackbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions