atfinho
4 months ago

Manual Login

Posted 4 months ago by atfinho

Hey Guys I'm trying to make a manual login in my application so I created a middleware to protect some routes from unauthorized user when I login it always redirects me back to the same page ..

I created isAuth middleware

<?php

namespace App\Http\Middleware;

use Closure;
use Auth;

class isAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (Auth::check()){
        return $next($request); }
        else{
           return redirect()->route('showLogin');
        }
    }
}

I have the login function below

      public function handleLogin(Request $request)
    {
        if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) {
            Auth::user();
            if (Auth::check()) {

                alert()->success('Succés!', 'Bienvenue!');
                return redirect()->route('showHome');
            } else {
                alert()->error('Oups!', 'Email ou Mot de passe incorrect !');
                return redirect()->back();
            }

        }

    }

this is Home Page route ( redirection after login)

Route::group(['module' => 'General', 'middleware' => ['isAuth'], 'namespace' => 'App\Modules\General\Controllers'], function() {

Route::get('/','[email protected]')->name('showHome');
});


Please sign in or create an account to participate in this conversation.