Skip to content

Commit

Permalink
Update user helper to report the exception so you know update the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelElrafa committed Nov 29, 2023
1 parent 1bbc4e9 commit 3417a4d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions app/helpers.php
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;
}
}
}

0 comments on commit 3417a4d

Please sign in to comment.