-
-
Notifications
You must be signed in to change notification settings - Fork 149
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. |
Note: This is not my original work, its a copy of #167 by @ggelashvili
Overview
This PR enhances the
Billable
middleware to provide better support for SPAs by allowing AJAX requests to receive a JSON response with a redirect URL. Currently,Billable
middleware and thebilling_enabled
configuration have no use for SPAs, & causes confusion which this PR aims to rectify.Changes
The updated
Billable
middleware now checks if the incoming request is an AJAX request and, if billing is enabled, returns a403
status code alongside a JSON response containing aforceRedirectUrl
field. This field provides a URL to which the SPA can redirect the user. The updated middleware assumes that thehost
parameter 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
403
status code, the front-end can now hook into the response interceptor, catch403
errors, extract the redirect URL from the response, and manage redirection on the front-end. This makes theBillable
middleware 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
Billable
middleware should not be used anyways for traditional SPAs.