How do I pass url query from login back to url?

Hi,

I’m having a problem figuring out how to pass a query from unlogged request to logged in request.

Tech involved nextjs version 14 and auth0

For example, with an unlogged in request:

https://mydomain.com?greeting=hello

I expect to get redirected to auth0 for authentication, then after that, redirected back to this url including the parameters

I have api/auth[auth0]/route.ts setup with login function set to returnTo: ‘/’, but how do I keep the original query parameters and pass them back after authentication?

I’ve tried checking req.nextUrl.searchParams in route.ts, but that doesn’t have any value. I also tried adding the query as a header in the the middleware.ts, but again this didn’t seem to get forced with the request.

Pretty sure this must be reasonably common, so any help pointing me in the right direction would be greatly appreciated.

Thank you in advance.