Skip to content

Commit f64d86d

Browse files
Add support for custom user model in AuthKitAuthenticationRequest (#15)
* Add support for custom user model in AuthKitAuthenticationRequest * Stop ignoring invalid return type error, as unknown class is no longer referenced * Update AuthKitAuthenticationRequest.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent de380cc commit f64d86d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ parameters:
33
- src
44

55
level: 0
6-
7-
ignoreErrors:
8-
- '#has invalid (return type|type) App\\Models\\User#'

src/Http/Requests/AuthKitAuthenticationRequest.php

Lines changed: 11 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,21 @@ 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+
80+
return $userModelClass::where('workos_id', $user->id)->first();
7981
}
8082

8183
/**
8284
* Create a user from the given WorkOS user.
8385
*/
84-
protected function createUsing(User $user): AppUser
86+
protected function createUsing(User $user): Authenticatable
8587
{
86-
/** @phpstan-ignore class.notFound */
87-
return AppUser::create([
88+
$userModelClass = Config::get('auth.providers.users.model');
89+
90+
return $userModelClass::create([
8891
'name' => $user->firstName.' '.$user->lastName,
8992
'email' => $user->email,
9093
'email_verified_at' => now(),
@@ -96,7 +99,7 @@ protected function createUsing(User $user): AppUser
9699
/**
97100
* Update a user from the given WorkOS user.
98101
*/
99-
protected function updateUsing(AppUser $user, User $userFromWorkOS): AppUser
102+
protected function updateUsing(Authenticatable $user, User $userFromWorkOS): Authenticatable
100103
{
101104
return tap($user)->update([
102105
// 'name' => $userFromWorkOS->firstName.' '.$userFromWorkOS->lastName,

0 commit comments

Comments
 (0)