-
-
Couldn't load subscription status.
- Fork 158
Enhancement: Improve BillableMiddleware for SPAs | revive PR #167 #437
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
base: master
Are you sure you want to change the base?
Conversation
|
Hi @rvibit thanks for the PR. Can you just fix the merge conflict, it is because we changed up how we handle the template engine to make the keys more generic i.e. SPA rather than REACT and MPA rather than Blade I'll re-review it and get it into the next release. |
f60e95d to
8e87d37
Compare
updated the PR, please check |
|
@rvibit did you do the Laracasts tutorial too? |
No I don't |
Oh, I've just realised! @ggelashvili from #167 is the guy that published the course on Laracasts! That's why I recognised it :) |
|
@rvibit have you checked if this is backwards compatible? Just trying to work out if we need to make this a major release if it breaks the existing SPA functionality. I assumed it would not, as we did not really have anything "workable" for SPA but wanted your input. |
It's backword compatible but there will be some confusion because Also I haven't tested it with MPA because I only have single app which is SPA, it'll work with MPA but if anyone from community watching this can confirm then that'll be good. |
|
Thanks for the context @rvibit if you are now throwing a 402, we probably want to update the wiki to advise how to handle it. |
I updated the wiki, I didn't know it'll get published without review, you can check it, or we can revert to last history if we need these updates after the merge
|


Note: This is not my original work, its a copy of #167 by @ggelashvili
Overview
This PR enhances the
Billablemiddleware to provide better support for SPAs by allowing AJAX requests to receive a JSON response with a redirect URL. Currently,Billablemiddleware and thebilling_enabledconfiguration have no use for SPAs, & causes confusion which this PR aims to rectify.Changes
The updated
Billablemiddleware now checks if the incoming request is an AJAX request and, if billing is enabled, returns a402status code alongside a JSON response containing aforceRedirectUrlfield. This field provides a URL to which the SPA can redirect the user. The updated middleware assumes that thehostparameter is included in the request, which can be easily implemented using an axios interceptor (if using axios on front-end).By returning a JSON response and a
402status code, the front-end can now hook into the response interceptor, catch402errors, extract the redirect URL from the response, and manage redirection on the front-end. This makes theBillablemiddleware more useful for SPAs.I added my own middleware in a project I'm working on with React front-end & worked perfectly, so thought it might be useful to improve the original Billable middleware.
Note that the wiki would need to be updated if this gets approved/merged.
This should not be a breaking change since
Billablemiddleware should not be used anyways for traditional SPAs.