2

有人请帮助我。我正在尝试实施社交名流身份验证,一切正常,但下Auth的路由不起作用。它们被重定向回登录页面。我的Auth或路由有什么问题。我的路线和控制器文件如下

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

控制器

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']
        ]);
    }
4

0 回答 0