社交网站google登录laravel 5.8中的客户端错误500

问题描述 投票:0回答:1

我有一个已经与Facebook登录集成的laravel项目,但是如果我使用Google登录,则该页面将引发500个服务器错误的客户端错误

您可以在此网站上查看https://indhri.asynchsolution.com并使用Google登录,不用担心,如果此问题得到解决,我会立即删除数据库

这是我的SocialController.php

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Laravel\Socialite\Facades\Socialite;
use Illuminate\Support\Facades\Auth;
use Spatie\Permission\Models\Role;
use App\SocialAccount;
use App\User;

class SocialiteController extends Controller
{
    public function redirectToProvider($provider)
    {
        return Socialite::driver($provider)->redirect();
    }

    public function handleProviderCallback($provider)
    {
        //$user = Socialite::driver($provider)->user();
         try {
            $user = Socialite::driver($provider)->user();
        } catch (Exception $e) {
            return redirect('/auth/login');
        }
        //dd($user);
        $authUser = $this->findOrCreateUser($user, $provider);

        Auth::login($authUser, true);
        return redirect('/personal');
    }

    public function findOrCreateUser($socialUser, $provider)
    {
        $socialAccount = SocialAccount::where('provider_id', $socialUser->getId())
                        ->where('provider_name', $provider)
                        ->first();

        if($socialAccount) {
            return $socialAccount->user;
        } else {
            $user = User::where('email', $socialUser->getEmail())->first();

            if(! $user) {
                $user = User::create([
                    'username' => $socialUser->getName(),
                    'email' => $socialUser->getEmail()

                ]);
                $user->assignRole('Registered');
            }

            $user->socialAccounts()->create([
                'provider_id' => $socialUser->getId(),
                'provider_name' => $provider
            ]);

            return $user;
        }
    }
}

This is the client error

this is error on Inspect

laravel laravel-socialite
1个回答
0
投票

SESSION_DOMAIN文件中添加.env

SESSION_DOMAIN=indhri.asynchsolution.com

或将config/session.phpnull更改为indhri.asynchsolution.com

'domain' => env('SESSION_DOMAIN', null),

清除缓存

php artisan config:clear
php artisan cache:clear

重新加载自动发现的程序包

composer dump-autoload

并在专用窗口上尝试,因为旧的会话cookie可能会引起问题

希望这会有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.