Support the ongoing development of Laravel.io →
posted 11 years ago
Authentication

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());
}

Unfortunately var_dump() returns null. What am I missing here? Any help would be appreciated! Thanks in advance!

Last updated 3 years ago.
0

Found the solution. Turns out that Laravel's Auth and Sentry are entirely independent. While using Sentry, Laravel's Auth will not work.

Sentry::getUser();

The above code will give you the details of the logged in user.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ananth99 ananth99 Joined 7 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.