Somebody please help me.I am trying to implement Socialite Authentication,everything works fine but routes under auth is not working.They are redirect back to login page.What is problem with my Auth or Routes.My Route and Controller files are below
Route::group(['middleware' => ['web']], function () {
Route::get('facebook',array(
'as' => 'facebook',
'uses' =>'FacebookController@redirectToProvider'
));
Route::get('Callback', 'FacebookController@handleProviderCallback');
});
Route::group(['middleware' => ['web','auth']], function () {
Route::get('play', function () {
return view('landing');
});
Route::get('go', function () {
return view('landing');
});
});
Controller
public function handleProviderCallback()
{
try
{
$user = Socialize::with('facebook')->user();
}
catch (Exception $e)
{
return Redirect::to('login');
}
$authUser = $this->findOrCreateUser($user);
Auth::login($authUser, true);
$user = Auth::user();
return Redirect::to('play');
}
private function findOrCreateUser($facebookUser)
{
if ($authUser = User::where('id', $facebookUser->getId())->first())
{
return $authUser;
}
return User::create([
'id' => $facebookUser->getId(),
'name' => $facebookUser->getName(),
'email' => $facebookUser->getEmail(),
'gender' => $facebookUser->user['gender'],
'avatar' => $facebookUser->getAvatar(),
'avatar_original' => $facebookUser->avatar_original,
'verified' => $facebookUser->user['verified']
]);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire