I am unable to authenticate using middleware auth from the Standard

Asked

Viewed 38 times

0

I can do normal authentication when I don’t put the routes inside a group.

When I put the routes that can only be accessed with login, the page does not redirect to the administrative area.

When I check what method Attempt of Auth is returning, it returns true and I can even view user data using the method dd(), but does not redirect me to the right page.

//Esse é meu arquivo Route
Route::get('/', 'Login\LoginController@index')->name('login');
Route::post('/login/entrar', 'Login\LoginController@entrar')->name('login.entrar');
Route::get('/login/sair','Login\LoginController@sair')->name('login.sair');


Route::group(['middleware'=>'auth'], function(){
 Route::get('/admin/exibir', 'Home\HomeController@index')->name('admin.exibir');
 Route::get('/admin/buscar', 'Home\HomeController@buscar')->name('admin.buscar'); 
});

<?php namespace App\Http\Controllers\Login;

use Illuminate\Http\Request; 
use App\Http\Controllers\Controller; 
use App\User; 
use Illuminate\Support\Facades\Auth;


class LoginController extends Controller 
{
    public function index()
    {
        return view('home');
    }

    public function entrar(Request $request)
    {   
        $dados = $request->All();
        if(Auth::attempt(['name'=>$dados['user'],'password'=>$dados['password']]))
        {
            return redirect()->route('admin.exibir');
        }
        else
        {
            return redirect()->route('login');
        }   
    }
    public function sair()
    {
        Auth::logout();
        return redirect()->route('login');
    }
}
  • You seem to have changed and built another authentication so you can put the Controller

  • Can yes, strange because I followed the same code I did once and it had worked, I thought it was version difference but it is not.

  • Your controller should be email or you changed in Model?

  • I changed the model to name

  • I do not understand well, what happens it does not redirect to the screen?

  • No, it enters the authentication method in the controller and authenticates, but when redirecting the page to the administrative page it goes back to the login screen.

  • So he is not authenticating ... and then it is investigation to know the reason, have to post the User model and have to see if he really created the session for you, I believe that not.

  • As I see if Session was created?

  • How to view Session? investigate in the area being generated which is in the folder storage/framework/sessions ... if it’s not changed that too

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.