Ad

Laravel 5.1 Auth Logs Out After Refresh

I'm working with Laravel for the first time. My auth user logs out automatically after i go to another route or if i refresh the page, and i dont understand why, please help me.

This is my log in code:

public function ini_ses(Request $datos)
{
    //Inicia sesion
    Session::put('ses_correo', Input::get('email'));

    $correo = $datos->input('email');
    $password= $datos->input('password');

    if(Auth::attempt(['correo_elec'=>$correo, 'password'=>$password]))
    {
        $_session['correo']=$correo;
        $_session['contra']=$password;

        if(Auth::user()->tipo==0)
        {
            return view('cliente');
        }
        elseif(Auth::user()->tipo==1)
        {
            return view('veterinario');
        }
        elseif(Auth::user()->tipo==2)
        {
            echo("Admin");
        }
    }
    else
    {
        var_dump($correo, $password);
    }

}

If you know how to fix it, i aprecciate your help.

Ad

Answer

UPDATE: Another possibility

Laravel 4 Auth works but does not stay logged in

Remove all, but the redirects. Apparently this may mess up the authentication process.


The Auth::attempt() should trigger the necessary things to keep the user logged in, a small yet simple possibility could be the remember me function. Although it shouldn't be that, it would be worth a try.

Add true as a second parameter to the function.

  if(Auth::attempt(['correo_elec'=>$correo, 'password'=>$password], true))

Assuming your Users table has the default laravel structure (with a remember token column)

Ad
source: stackoverflow.com
Ad