Hello. I am working with Laravel 8 and wanted a way to prevent users from hitting the back button after logout and thus re-entering the dashboard. I am using a middleware called preventBackHistory and it is working great. However, because I am wipping the session, the role no longer exists and I am ending up on a page that returns null. What I am trying to do is if there is no role or I get some kind of null value, that I am redirected to my view.errors.404 page. So far, I am not clear on what needs to be done to make this happen.
So, in my Home controller, I am running the following check in my index method:
public function index() {
dd(Auth::user());
$role = Auth::user()->role;
if($role == 1) {
return view('admin.index');
} elseif($role == 0) {
return view('user.index');
} else {
return view('errors.404');
}
}
my redirects route calling my index method is as follows:
Route::get('redirects', [HomeController::class, 'index']);
and when I hit the back button, my browser is taking me to http://127.0.0.1:8000/redirects and when doing a dd on the value of Augh::user(); I obviously get null.
Can anyone help me come up with a better solution to handle what I am trying to do? I would certainly appreicate it. Thank you in advance.