#Ryan_Whipple - Portal Redirect

1 messages ยท Page 1 of 1 (latest)

scarlet barn
#

Hello again! It sounds like you're trying to load the endpoint that redirects to the portal using JavaScript (like with fetch() or similar) instead of sending the person to that URL.

#

Does that make sense?

serene hemlock
#

Hello! That's definitely possible. I changed the template form from HTML to a React component and made the endpoint on the right with a hard-coded customer for now.

scarlet barn
#

Yeah, you don't want to use axios.post with that URL, you want to send the person to it.

serene hemlock
#

gotcha. I figured axios.post would be equivalent to form method="POST" in this instance but I can see why that isn't the case

scarlet barn
#

Yeah, they're pretty different in a situation like this. ๐Ÿ™‚

serene hemlock
#

alright, then this may be a really embarrassing question, but if I just go back to the regular <form> template, I get this error message: Cannot POST /create-customer-portal-session

#

and that's with the server-side code taken right out of the docs

scarlet barn
#

What does your server's code look like that defines the route?

#

Oh, it's in your screenshot.

#

Hang on...

#

Does it work without those CORS options in there?

#

If not, is there any further detail about that error? Are you seeing that in the browser console or server side?

serene hemlock
#

removing CORS options doesn't change anything. That error message pops up in the browser main window, nothing comes back in either console

scarlet barn
#

What's the URL in the browser when that's displayed? Is it your /create-customer-portal-session URL?

serene hemlock
scarlet barn
#

Any further detail in your server logs?

serene hemlock
#

my React app is running on 3000, the server is 4000

scarlet barn
#

Wait... what?

#

If you're running the server on a different port it sounds like you didn't specify that port in the URL you're posting to?

#

You need to post to http://localhost:4000/create-customer-portal-session but it sounds like you might be posting to a relative URL like /create-customer-portal-session instead, which would inherit the origin (including the port) of your React app.

serene hemlock
#

๐Ÿคฆโ€โ™‚๏ธ

#

I knew the URL in the browser should have been 4000. I did it in the axios request, but not the form

#

it works now

scarlet barn
#

Awesome! ๐Ÿ™‚

serene hemlock
#

lol, thanks a bunch! I really appreciate your help. I'm 2 months out of a coding bootcamp and working on projects with other alums, trying to get some real-world experience. Helping this guy set up his site is my first time working with Stripe. Seems like a good skillset to have since it's everywhere

scarlet barn
#

Absolutely! This stuff can be tricky, and the error you made is common even among experienced developers. ๐Ÿ™‚