[2.x] Environment APP_URL added into the default sanctum.stateful configuration #264
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Added the application's URL from
.env
'sAPP_URL
to the default value ofsanctum.stateful
configuration.Why?
In my experience (teaching new Laravel developers) not having the application's URL among default stateful domains leads to a lot of headache when deploying to a production environment. The URL changes from e.g.
localhost:3000
towww.test.com
and suddenly a new configuration value must be added into.env
which was not needed until now.While everyone expects they should change the
APP_URL
when moving to a new environment, few also remember to addSANCTUM_STATEFUL_DOMAINS
This is also hard to notice because the application works, only the requests which should be authenticated are not.
How?
Added the host part of the
APP_URL
environment value to/config/sanctum.php
Testing
I needed to modify the
phpunit.xml.dist
file to provide a sample envAPP_URL
configuration that could be loaded with theenv()
function.Tests test the presence of the host of
env('APP_URL')
inconfig('sanctum.stateful'
) and that a request coming from the environmentAPP_URL
configuration passes theLaravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::fromFrontend()
check.Duplicite PR?
This may seem like a duplicite of #243 but does the same thing with much simpler code and the test suite passes.