I have been trying to redirect the user after session timeout, but when using spatie permissions package i cant get the TokenMismatchException for the session timeout, i always get UnauthorizedException. Here is my Exceptions/Handler.php file:
public function render($request, Exception $exception)
{
if ($exception instanceof TokenMismatchException){
session()->flash('warning','Session timeout. Please login again.');
return redirect()->guest(route('login'));
}
if ($exception instanceof \Spatie\Permission\Exceptions\UnauthorizedException){
return redirect('/restricted');
}
return parent::render($request, $exception);
}
How to catch the session timeout exception and make a custom redirect in this case?