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;
|
|
|
|
|
2022-03-24 14:58:30 +01:00
|
|
|
class RejectIfAuthenticated
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2021-12-02 13:15:53 +01:00
|
|
|
* @param string|null ...$guards
|
2019-05-20 07:37:41 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2021-12-02 13:15:53 +01:00
|
|
|
public function handle(Request $request, Closure $next, ...$guards)
|
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);
|
|
|
|
}
|
|
|
|
}
|