Complicated redirect from Netlify Function with parameters and wildcard

Hi! I am having trouble setting up my redirect. I have an oauth link on my site that takes the user to Stripe, which redirects them to my site and has varying parameters depending on what information is filled out on Stripe.

I do not care about passing the parameters through to the redirect because the netlify function they are first directed to saves all of that info to my database.
The from URL looks like:

http://localhost:8888/.netlify/functions/authorize-connect-account?state=6543AFDA4325cdsa52&scope=read_write&code=ac_352FAS235casd2FAFAS

There may be more parameters than scope and code. I am not sure what they will be, but I don’t need to pass them to the to redirect so I would like to use a wildcard.

The to URL looks like https://localhost:8888/provider-dashboard

My netlify.toml looks like this (the first redirect works fine):

# example netlify.toml
[build]
  command = "yarn build"
  functions = "functions"
  publish = "public"

## Uncomment to use this redirect for Single Page Applications like create-react-app. 
## Not needed for static site generators.
[[redirects]]
  from = "/room/*"
  to = "/room"
  status = 200

[[redirects]]
  from = "/.netlify/functions/authorize-connect-account*"
  to = "/provider-dashboard"
  status = 200

I have tried using query = {state = ":state"},

from = "/.netlify/functions/*"
to= "/provider-dashboard:splat"

and have looked at Redirect options | Netlify Docs.
I think the problem might be that I either need to include every query parameter or that the wildcard is not after a /.

Whatever change I make, I receive the following error Invalid /.netlify path in redirect source

Any help is greatly appreciated!

I created a small demo site and I’ve included what my _redirects rule is.

/authorize-connect-account state=:state /provider-dashboard?state=:state 200!

In this example: /authorize-connect-account?state=101 will proxy (200!) redirect to /provider-dashboard?state=101

It strips any additional query parameters for you.

I hope this helps! Redirects are pretty powerful :+1:.

Thank you for the reply!
Apparently this was a bit trickier than I had originally thought. My understanding is now that if I had used the 200 redirect, it wouldn’t have invoked my netlify function correctly. So, what I did was added this code to my netlify function and it redirects perfectly while invoking my function to add the info passed to my url into my database.

return {
            statusCode: 302,
            body: JSON.stringify({ msg: response }),
            headers: {
                location: "/provider-dashboard"
            }
        }
2 Likes

Snazzy, I like it! :partying_face: