2022-07-12 12:32:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
|
|
class SkipIfAuthenticated
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param string|null ...$guards
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle(Request $request, Closure $next, ...$guards)
|
|
|
|
{
|
|
|
|
$guards = empty($guards) ? [null] : $guards;
|
|
|
|
|
|
|
|
foreach ($guards as $guard) {
|
|
|
|
if (Auth::guard($guard)->check()) {
|
2023-03-15 11:46:37 +01:00
|
|
|
$user = Auth::guard($guard)->user();
|
2022-07-12 12:32:32 +02:00
|
|
|
|
|
|
|
return response()->json([
|
2023-03-26 17:13:32 +02:00
|
|
|
'message' => 'authenticated',
|
|
|
|
'name' => $user->name,
|
2023-03-15 11:46:37 +01:00
|
|
|
'preferences' => $user->preferences,
|
2022-07-12 12:32:32 +02:00
|
|
|
], 200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|