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!
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community