I added a check in LoginController to limit the user's max number of connected devices.
I added the following in the login() method in LoginController :
public function login(Request $request)
{
// ... some code ...
if ($this->attemptLogin($request)) {
$user = Auth::user();
if ($user->max_devices >= 5) {
return $this->sendMaxConnectedDevicesResponse($request);
}
}
// ... some code ...
}
protected function sendMaxConnectedDevicesResponse(Request $request)
{
throw ValidationException::withMessage([
$this->username() => ['Device limit reached'])
->status(403);
}
sendMaxConnectedDevicesResponse is a copy of sendLockoutResponse with my custom message, however I get warning that I have an unhandled exception (Unhandled Illuminate\Validation\ValidationException).
So how can I handle it like sendLockoutResponse handles it, so that it will show as an error in the frontend, instead of just ignoring it? Right now what happens is that even though it throws the error, it doesn't show it in the frontend, and it continues to login as usual