2016-07-09 2 views
1

나는 정확하게이 문서를 따르고 있습니다.페이스 북의 Laravel Socialite는 로그인하지 않았습니다

https://github.com/laravel/socialite

내가 페이스 북에 내 응용 프로그램을 작성 작업의 모든있어 https://laravel.com/docs/5.1/authentication#social-authentication. Facebook 버튼으로 로그인 할 때, 앱을 인증하고 다시 내 사이트로 이동합니다. 그러나 로그인 한 것으로 표시되지 않습니다. 아래의 리디렉션 대신 dd()를 사용하면 Facebook 계정에서 모든 데이터를 가져옵니다. 그러나 로그인 한 사용자에게만 표시되는 페이지는 표시되지 않습니다.

Route::get('login/facebook', 'Auth\[email protected]'); 
Route::get('login/facebook/callback', 'Auth\[email protected]'); 

사교계가 composer.json에 제대로 설치되어 : 여기

public function redirectToProvider() 
{ 
    return Socialite::driver('facebook')->redirect(); 
} 

public function handleProviderCallback() 
{ 
    $user = Socialite::driver('facebook')->user(); 

    return redirect('my-profile') 
      ->with('message', 'You have signed in with Facebook.'); 
} 

내 경로입니다

여기 내 컨트롤러입니다. 클래스는 config/app.php에 있고 FB 앱의 ID는 config/services.php에 있습니다.

왜 작동하지 않는가에 대한 아이디어가 있습니까?

답변

2

handleProviderCallback 메서드에서 드라이버가 반환 한 사용자를 만들고 인증해야합니다.

$userModel = User::firstOrNew(['email' => $user->getEmail()]); 
if (!$userModel->id) { 
    $userModel->fill([.....]); 
    $userModel->save(); 
} 

그런 다음 사용자를 인증 : 존재하지 않는 경우

사용자를 작성

Auth::login($userModel); 

귀하의 방법은 다음과 같이 표시됩니다

public function handleProviderCallback() { 
    $user = Socialite::driver('facebook')->user(); 

    $userModel = User::firstOrNew(['email' => $user->getEmail()]); 
    if (!$userModel->id) { 
     $userModel->fill([.....]);//Fill the user model with your data 
     $userModel->save(); 
    } 

    Auth::login($userModel); 

    return redirect('my-profile') 
      ->with('message', 'You have signed in with Facebook.'); 
} 
관련 문제