-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update user helper to report the exception so you know update the code.
- Loading branch information
1 parent
1bbc4e9
commit 3417a4d
Showing
1 changed file
with
13 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
<?php | ||
|
||
use App\Models\User; | ||
use Illuminate\Auth\AuthenticationException; | ||
use Illuminate\Auth\SessionGuard; | ||
use Illuminate\Support\Facades\Auth; | ||
use Smpita\TypeAs\TypeAs; | ||
|
||
if (! function_exists('user')) { | ||
function user(string $guard = 'web'): User | ||
{ | ||
$user = auth($guard)->user(); | ||
if (! $user instanceof User) { | ||
throw new RuntimeException('No user authenticated.'); | ||
} | ||
try { | ||
return TypeAs::class( | ||
User::class, | ||
TypeAs::class(SessionGuard::class, Auth::guard($guard))->authenticate() | ||
); | ||
} catch (AuthenticationException $e) { | ||
report(new RuntimeException('User not authenticated.', previous: $e)); | ||
|
||
return $user; | ||
throw $e; | ||
} | ||
} | ||
} |