How to change the redirect when entering the Login Route via a back button after authentication in Laravel?

Viewed 20

I have a middleware that redirects to the Login page and everything works fine:

*If I try to enter a page restricted by this middleware I am sent to login page and then I'm sent to that page.

*If I type /login directly, I will be redirected to /about.

I'm using a custom guard called "client".

Here is my code:

<?php

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Auth;
use Closure;

class ClientLoggedIn
{
    public function handle($request, Closure $next)
    {
        if (!Auth::guard('client')->check()) {
            session(['url.intended' => url()->full()]);
            return redirect()->route('login');
        }
        return $next($request);
    }
}


<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

class LoginController extends Controller
{

    use AuthenticatesUsers;

    protected function redirectTo()
    {
        $intendedURL = request()->session()->get('url.intended');
        if (isset($intendedURL)) {
            return $intendedURL;
        } 
        return '/about';
    }

    public function __construct()
    {
        $this->middleware('guest:client')->except('logout');
    }

    protected function guard()
    {
        return Auth::guard('client');
    }

    public function showLoginForm()
    {
        return view('auth.login');
    }
}

Whenever I click the back button after the authentication, however, a redirect to the site home (localhost:8000/) occurs (the back button refers to /login)

My question is: is there some configuration or callback that sets it to the home? I thought it would be the redirectTo, but it doesn't seem to be it since it is already set to /about. For what I know, when I click back doesn't occur a request to the server, so, how it works and how to change it?

Thanks in advance.

0 Answers
Related