Skip to content

WorkOS not working with cached config #55028

Closed
laravel/workos
#7
@rolandorojas

Description

@rolandorojas

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

  1. Create a new laravel app
  2. Select the livewire starter kit
  3. Select workos as the auth provider
  4. Create a WorkOS account and set your credentials in your .env file.
  5. Try to log in. It should work normally.
  6. Clear your cookies and run php artisan config:cache
  7. Try to log in again. You should now see a WorkOS\Exception\ConfigurationException with message "$apiKey is required"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions