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.

Hi @noelt.dolan,

Thanks for posting your question and sorry for the late reply.

You can send custom query parameters when performing an /authorize request by using AuthorizationParameters documented here for the NextJs v4.0.3, that should like this:

Additionally you can also check out this Knowledge Article about Passing Additional Parameter to the Universal Login URL.

I hope this help your use case, but others as well.
Thanks,
Remus

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.