2019-05-20 07:37:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
2021-12-02 13:15:53 +01:00
|
|
|
use Illuminate\Http\Request;
|
2019-05-20 07:37:41 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2023-08-01 11:26:58 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2019-05-20 07:37:41 +02:00
|
|
|
|
2022-03-24 14:58:30 +01:00
|
|
|
class RejectIfAuthenticated
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2023-08-01 11:26:58 +02:00
|
|
|
* @param \Closure(\Illuminate\Http\Request) : (\Symfony\Component\HttpFoundation\Response) $next
|
2019-05-20 07:37:41 +02:00
|
|
|
*/
|
2023-08-01 11:26:58 +02:00
|
|
|
public function handle(Request $request, Closure $next, string ...$guards) : Response
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2021-12-02 13:15:53 +01:00
|
|
|
$guards = empty($guards) ? [null] : $guards;
|
|
|
|
|
|
|
|
foreach ($guards as $guard) {
|
|
|
|
if (Auth::guard($guard)->check()) {
|
2022-11-22 15:15:52 +01:00
|
|
|
return response()->json(['message' => __('auth.already_authenticated')], 400);
|
2021-12-02 13:15:53 +01:00
|
|
|
}
|
2019-05-20 07:37:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|