Skip to content

Commit f3a6347

Browse files
committed
Add support for custom user model in AuthKitAuthenticationRequest
1 parent de380cc commit f3a6347

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/Http/Requests/AuthKitAuthenticationRequest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace Laravel\WorkOS\Http\Requests;
44

5-
use App\Models\User as AppUser;
65
use Illuminate\Auth\Events\Registered;
6+
use Illuminate\Contracts\Auth\Authenticatable;
77
use Illuminate\Foundation\Http\FormRequest;
88
use Illuminate\Support\Facades\Auth;
9+
use Illuminate\Support\Facades\Config;
910
use Illuminate\Support\Facades\URL;
1011
use Inertia\Inertia;
1112
use Laravel\WorkOS\User;
@@ -72,19 +73,19 @@ public function authenticate(?callable $findUsing = null, ?callable $createUsing
7273
/**
7374
* Find the user with the given WorkOS ID.
7475
*/
75-
protected function findUsing(User $user): ?AppUser
76+
protected function findUsing(User $user): ?Authenticatable
7677
{
77-
/** @phpstan-ignore class.notFound */
78-
return AppUser::where('workos_id', $user->id)->first();
78+
$userModelClass = Config::get('auth.providers.users.model');
79+
return $userModelClass::where('workos_id', $user->id)->first();
7980
}
8081

8182
/**
8283
* Create a user from the given WorkOS user.
8384
*/
84-
protected function createUsing(User $user): AppUser
85+
protected function createUsing(User $user): Authenticatable
8586
{
86-
/** @phpstan-ignore class.notFound */
87-
return AppUser::create([
87+
$userModelClass = Config::get('auth.providers.users.model');
88+
return $userModelClass::create([
8889
'name' => $user->firstName.' '.$user->lastName,
8990
'email' => $user->email,
9091
'email_verified_at' => now(),
@@ -96,7 +97,7 @@ protected function createUsing(User $user): AppUser
9697
/**
9798
* Update a user from the given WorkOS user.
9899
*/
99-
protected function updateUsing(AppUser $user, User $userFromWorkOS): AppUser
100+
protected function updateUsing(Authenticatable $user, User $userFromWorkOS): Authenticatable
100101
{
101102
return tap($user)->update([
102103
// 'name' => $userFromWorkOS->firstName.' '.$userFromWorkOS->lastName,

0 commit comments

Comments
 (0)