Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom Search Params in the redirectTo option URL #96

Closed
413n opened this issue May 12, 2022 · 1 comment · Fixed by #364
Closed

Support for custom Search Params in the redirectTo option URL #96

413n opened this issue May 12, 2022 · 1 comment · Fixed by #364
Labels
enhancement New feature or request hacktoberfest nextjs Next.js specific functionality

Comments

@413n
Copy link

413n commented May 12, 2022

I have a middleware using withAuthMiddleware that redirects the user to the homepage with a custom Search param and seems to not be supported because I get to this broken link: http://localhost:3000/%3Ferror=notAuthorized?redirectedFrom=%2Fprotected%2Fpage

My code

import { withMiddlewareAuth } from "@supabase/auth-helpers-nextjs/middleware";

export const middleware = withMiddlewareAuth({
  redirectTo: "/?error=notAuthorized",
});

Debugging the code, I found the part below where we can see that the redirectTo is set as pathname and then a SearchParam is set. This is the part that could be more flexible.

https://github.com/supabase-community/auth-helpers/blob/9b4225133a5f3a617819570bd172af3cdb8ac7cb/packages/nextjs/src/middleware/withMiddlewareAuth.ts#L142-L159

Proposal

What if we check that the redirectTo is an instanceof URL (https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) and eventually avoiding setting it to the pathname but using that to set the SearchParam?

Or eventually an additional check should be done to initialize the given URL string

@thorwebdev
Copy link
Member

This will be enabled via #364

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest nextjs Next.js specific functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants