-
Notifications
You must be signed in to change notification settings - Fork 0
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
Can't load forms in a headless single page application in different domain / Improve error handling among other things #9
Comments
So... When used normally, WPLF adds an object to window.wplfData. The object looks something like this.
Obviously I have already replaced the actual domain with the variable in the example, but this is more or less what you get. The JS in the plugin requires this object to work, and the JS in this component requires the JS in the plugin to work, so you can't skip this. So here's where it gets interesting. Because we add the nonce to the base request headers, all form submissions by users who are logged in will be authenticated, when we're dealing with traditional WordPress with cookies and shit. If you use this component in a WordPress site, it will work like you'd expect. However, when you use the component in a single page application, you lose the standard authentication of WordPress which works with cookies. This means that there will be no WP cookies sent with the submission, and getting the nonce from the API is a terrible idea. While you can do it, don't. I've already done it so you wouldn't have to. So... Let's say you copypasted the wplfData object and you're getting a 403 when you try to load a form. Behind that 403 is more than likely to be a "nonce is invalid" error message, at which point I wouldn't blame you if you wanted to facedesk. Worry not. I give you 3 options.
|
Describe the bug
If this component is used without a window.wplfData in place, it will fail with a cryptic "Unexpected token at 0".
If the request to the form is 403'd for some reason (nonce!!) it will display the loading state forever, in my case:
To Reproduce
Steps to reproduce the behavior:
In other words, headless single page applications are in quite a spot at the moment.
The text was updated successfully, but these errors were encountered: