From f3a6347a7d62501526fb7fc4daa3104351219a00 Mon Sep 17 00:00:00 2001 From: Zach Gilbert Date: Fri, 26 Sep 2025 14:29:31 +0100 Subject: [PATCH 1/3] Add support for custom user model in AuthKitAuthenticationRequest --- .../Requests/AuthKitAuthenticationRequest.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Http/Requests/AuthKitAuthenticationRequest.php b/src/Http/Requests/AuthKitAuthenticationRequest.php index 2c932cb..f1e0ab8 100644 --- a/src/Http/Requests/AuthKitAuthenticationRequest.php +++ b/src/Http/Requests/AuthKitAuthenticationRequest.php @@ -2,10 +2,11 @@ namespace Laravel\WorkOS\Http\Requests; -use App\Models\User as AppUser; use Illuminate\Auth\Events\Registered; +use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\URL; use Inertia\Inertia; use Laravel\WorkOS\User; @@ -72,19 +73,19 @@ public function authenticate(?callable $findUsing = null, ?callable $createUsing /** * Find the user with the given WorkOS ID. */ - protected function findUsing(User $user): ?AppUser + protected function findUsing(User $user): ?Authenticatable { - /** @phpstan-ignore class.notFound */ - return AppUser::where('workos_id', $user->id)->first(); + $userModelClass = Config::get('auth.providers.users.model'); + return $userModelClass::where('workos_id', $user->id)->first(); } /** * Create a user from the given WorkOS user. */ - protected function createUsing(User $user): AppUser + protected function createUsing(User $user): Authenticatable { - /** @phpstan-ignore class.notFound */ - return AppUser::create([ + $userModelClass = Config::get('auth.providers.users.model'); + return $userModelClass::create([ 'name' => $user->firstName.' '.$user->lastName, 'email' => $user->email, 'email_verified_at' => now(), @@ -96,7 +97,7 @@ protected function createUsing(User $user): AppUser /** * Update a user from the given WorkOS user. */ - protected function updateUsing(AppUser $user, User $userFromWorkOS): AppUser + protected function updateUsing(Authenticatable $user, User $userFromWorkOS): Authenticatable { return tap($user)->update([ // 'name' => $userFromWorkOS->firstName.' '.$userFromWorkOS->lastName, From 9e621a92c6612734b7cdfd029d07939e9adc6a56 Mon Sep 17 00:00:00 2001 From: Zach Gilbert Date: Fri, 26 Sep 2025 14:52:57 +0100 Subject: [PATCH 2/3] Stop ignoring invalid return type error, as unknown class is no longer referenced --- phpstan.neon.dist | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 2baffc3..5b79b49 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,6 +3,3 @@ parameters: - src level: 0 - - ignoreErrors: - - '#has invalid (return type|type) App\\Models\\User#' From 8063f761ba1fd93427ca72731e97ac55c5baae4a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 26 Sep 2025 10:46:29 -0500 Subject: [PATCH 3/3] Update AuthKitAuthenticationRequest.php --- src/Http/Requests/AuthKitAuthenticationRequest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Http/Requests/AuthKitAuthenticationRequest.php b/src/Http/Requests/AuthKitAuthenticationRequest.php index f1e0ab8..8eb5947 100644 --- a/src/Http/Requests/AuthKitAuthenticationRequest.php +++ b/src/Http/Requests/AuthKitAuthenticationRequest.php @@ -76,6 +76,7 @@ public function authenticate(?callable $findUsing = null, ?callable $createUsing protected function findUsing(User $user): ?Authenticatable { $userModelClass = Config::get('auth.providers.users.model'); + return $userModelClass::where('workos_id', $user->id)->first(); } @@ -85,6 +86,7 @@ protected function findUsing(User $user): ?Authenticatable protected function createUsing(User $user): Authenticatable { $userModelClass = Config::get('auth.providers.users.model'); + return $userModelClass::create([ 'name' => $user->firstName.' '.$user->lastName, 'email' => $user->email,