Question

I'm building an authentication system using Sentry 2. The problem I'm facing is that I'm unable to create a session for the user after he's authenticated and logged in via Sentry. This is my controller code:

public function postLogin()
{
    $credentials = array(
        'email' => Input::get('email'),
        'password' => Input::get('password')
    );

    try 
    {
        $user = Sentry::authenticate($credentials, false);
        if ($user)
        {
            if(Input::get('remember')=='true')
                Sentry::loginAndRemember($user);     
        }
    }
    catch(\Exception $e)
    {
        return View::make('hello')->withErrors(array('login' => $e->getMessage()));
    }
    try
    {
        Sentry::login($user, false);
    }
    catch (Cartalyst\Sentry\Users\LoginRequiredException $e)
    {
        echo 'Login field is required.';
    }
    catch (Cartalyst\Sentry\Users\UserNotActivatedException $e)
    {
        echo 'User not activated.';
    }
    catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    {
        echo 'User not found.';
    }
}

After I log in, to check if the user is actually logged in, I made another controller action which dumps the Authenticated user details:

public function index()
{
    var_dump(Auth::user());
}

var_dump() returns null. What am I missing here? I'm new to Laravel and Sentry. Any help would be appreciated! Thanks in advance!

Was it helpful?

Solution

If you are going to use Sentry, you no longer use Laravels Auth. They are completely independent of one another.

Instead, you now use

$user = Sentry::getUser();

See https://cartalyst.com/manual/sentry/users/find

OTHER TIPS

To access sentry session user use this {{Sentry::getUser()}}

Auth::user() return laravel session object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top