0
votes

I created a custom authentication for my Laravel app following that tutorial: https://medium.com/@nasrulhazim/laravel-using-different-table-and-guard-for-login-bc426d067901

I adapted it to my needs but I didn't have to change much.

In the end, when I try to go the the /home route, but it says: "Route [login] not defined."

My guess is that a default behavior of the authentication call the login route instead of the /fidelite/login I've created.

Here is my provider:

fidelite' => [
            'driver' => 'eloquent',
            'model' => App\Fidelite::class,
        ],

And the guard

'fidelite' => [
            'redirectTo' => 'fidelite.home',
            'driver' => 'session',
            'provider' => 'fidelite',
        ],

The routes defined in the web.php file

Route::prefix('fidelite')
    ->as('fidelite.')
    ->group(function() {
        Route::get('/home', 'Home\FideliteHomeController@index')->name('home');
Route::namespace('Auth\Login')
      ->group(function() {
    Route::get('login', 'FideliteController@showLoginForm')->name('login');
    Route::post('login', 'FideliteController@login')->name('login');
    Route::post('logout', 'FideliteController@logout')->name('logout');
    Route::get('register', 'FideliteController@showRegisterForm')->name('register');
      });
 });

Basically, there is two controllers; the first one, FideliteController adds the middleware and show the needed forms to login / register

class FideliteController extends DefaultLoginController
{
    protected $redirectTo = '/fidelite/home';
    public function __construct()
    {
        $this->middleware('guest:fidelite')->except('logout');
    }
    public function showLoginForm()
    {
        return view('auth.login.fidelite');
    }
    public function showRegisterForm()
    {
        return view('auth.compte');
    }
    public function username()
    {
        return 'email';
    }
    protected function guard()
    {
        return Auth::guard('fidelite');
    }
}

And the other one returns the /fidelite/home page when the user is logged

class FideliteHomeController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth:fidelite');
    }
    public function index()
    {
        return view('home.fidelite');
    }
}

There is something I missing, but what ?

Many thanks for your help and time...

2
Actually your login route has name fidelite.login because of the group as and has duplicate names fidelite.login.The Alpha
that's right and if I go the the /fidelite/login it works. But when I call the /home/fidelite route, I've got an InvalidArgumentException - Route [login] not defined. I think it somehow call the /login routeLaurent Kreps
That's probably because your home page has template where you've used the route('login') to generate the login link.The Alpha
Also, check the middleware which is referenced/used in FideliteHomeController ::constructor by $this->middleware('auth:fidelite'); it may have used any redirection of login.The Alpha
I don't think it's the issue I encounter because when I edit my FideliteHomeController and replace return view('home.fidelite'); in the index function by return 'hello';, the same error occursLaurent Kreps

2 Answers

0
votes

Found it ! Thanks to the Alpha whom helps me find the problem !

The problem was that the middleware I was using (Authenticate.php) was redirecting to the route('login') instead of the custom route I needed.

0
votes

You are duplicating the login name route. change the name of login to any specific name that properly define your route behavior.