I have seen this error mentioned on a few threads.
nextjs-auth0 is attempting to set cookies from a server component, see GitHub - auth0/nextjs-auth0: Next.js SDK for signing in with Auth0
I am using refresh tokens and I understand this error means that if the access token has expired, a new one will be requested every time due to the cookie not being updated. Most solutions point to using withMiddlewareAuthRequired
. I have a multi-tenant app, each customer has their own Auth0 setup so I am instantiating my own Auth0 client using initAuth0
for each domain e.g. example1.com uses tenant 1, and example2.com uses tenant 2.
The tricky part is that I am using the crypto
module to decrypt the client secret, so I can’t instantiate auth0 in the middleware as crypto
is not available on the edge runtime. Is there any other way of accessing the session outside of a server component in order to update it? My only thought currently is to setup polling on the client to an API route that accesses the session, as this will be using a Node runtime, not the edge. I don’t really need any other API routes currently as all of the data fetching logic is within the server components.
Any help would be great!