Nextjs-auth0: withPageAuthRequired not redirecting to the correct url if there are multiple url params

Created on 27 Mar 2021  路  2Comments  路  Source: auth0/nextjs-auth0

Describe the problem

I have an SSR page that is protected by withPageAuthRequired. The url for this page is in the format of http://localhost:3000/events?city=some-city&start=xxxx-xx-xx&end=xxxx-xx-xx.

When I'm logged in I have no problem accessing this page. When I'm not logged in I am redirected to the login page as expected. The problem is after logging in, I am redirected to http://localhost:3000/events?city=some-city. The rest of the url is not included in the redirect.

What was the expected behavior?

I should be redirected to the correct url which includes all the url/query string params.

I checked the network tab on Chrome and this is the url requested when I'm being redirected to the login page: http://localhost:3000/api/auth/login?returnTo=/events?city=some-city&start=xxxx-xx-xx&end=xxxx-xx-xx

I expect the returnTo url param to equal /events?city=some-city&start=xxxx-xx-xx&end=xxxx-xx-xx but that is not the case. There are actually 3 url params here:

  • returnTo: /events?city=some-city
  • start: xxxx-xx-xx
  • end: xxxx-xx-xx

The returnTo value will only include the url up to the first url/query string param.

Environment

  • Version of this library used: 1.3.0
  • Which framework are you using, if applicable:next 10.0.7
bug

Most helpful comment

@kpatel27 - have raised some work internally to fix this

All 2 comments

Thanks for reporting this @kpatel27

Looks like we need to encodeURIComponent somewhere - will investigate

@kpatel27 - have raised some work internally to fix this

Was this page helpful?
0 / 5 - 0 ratings