-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathLogin.php
More file actions
35 lines (27 loc) · 801 Bytes
/
Login.php
File metadata and controls
35 lines (27 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace App\GraphQL\Mutations;
use App\Models\User;
use GraphQL\Error\Error;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
final class Login
{
/**
* @param null $_
* @param array{email: string, password: string} $args
*/
public function __invoke($_, array $args): User
{
$guardConfig = config('sanctum.guard');
assert(is_array($guardConfig));
$guardName = Arr::first($guardConfig);
assert(is_string($guardName));
$guard = Auth::guard($guardName);
if( ! $guard->attempt($args)) {
throw new Error('Invalid credentials.');
}
$user = $guard->user();
assert($user instanceof User, 'must receive User after successful login');
return $user;
}
}