Description
Laravel Version
12
PHP Version
8.4
Database Driver & Version
No response
Description
The WorkOS integration breaks when running php artisan config:cache
The reason seems to be that the workos-php
package tries to get the API key using an environment variable, which stops working after the configuration is cached. If you try to log in with the configuration cached, you will get a WorkOS\Exception\ConfigurationException
Here is the relevant stacktrace:
$apiKey is required {"exception":"[object] (WorkOS\\Exception\\ConfigurationException(code: 0): $apiKey is required at C:\\Projects\\Experiments\\test\\vendor\\workos\\workos-php\\lib\\WorkOS.php:52)
[stacktrace]
#0 C:\\Projects\\Experiments\\test\\vendor\\workos\\workos-php\\lib\\UserManagement.php(750): WorkOS\\WorkOS::getApiKey()
#1 C:\\Projects\\Experiments\\test\\vendor\\laravel\\workos\\src\\Http\\Requests\\AuthKitAuthenticationRequest.php(28): WorkOS\\UserManagement->authenticateWithCode('****', '****')
#2 C:\\Projects\\Experiments\\test\\routes\\auth.php(13): Laravel\\WorkOS\\Http\\Requests\\AuthKitAuthenticationRequest->authenticate()
#3 C:\\Projects\\Experiments\\test\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\helpers.php(399): Illuminate\\Routing\\RouteFileRegistrar->{closure}(Object(Illuminate\\Http\\RedirectResponse))
#4 C:\\Projects\\Experiments\\test\\routes\\auth.php(13): tap(Object(Illuminate\\Http\\RedirectResponse), Object(Closure))
Steps To Reproduce
- Create a new laravel app
- Select the
livewire
starter kit - Select
workos
as the auth provider - Create a WorkOS account and set your credentials in your
.env
file. - Try to log in. It should work normally.
- Clear your cookies and run
php artisan config:cache
- Try to log in again. You should now see a
WorkOS\Exception\ConfigurationException
with message "$apiKey is required"