Reputation: 11
I am working on login with social account and currently I am testing with Google account. I used Laravel Socialite and read documentation and did everything. I share my code below, anyone have an idea what I did wrong?
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Socialite;
use Auth;
use Exception;
use App\User;
class GoogleController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function redirectToGoogle()
{
return Socialite::driver('google')->redirect();
}
/**
* Create a new controller instance.
*
* @return void
*/
public function handleGoogleCallback()
{
try {
$user = Socialite::driver('google')->user();
$finduser = User::where('google_id', $user->id)->first();
if($finduser){
Auth::login($finduser);
return redirect('/home');
}else{
$newUser = User::create([
'name' => $user->name,
'email' => $user->email,
'google_id'=> $user->id,
'password' => encrypt('123456dummy')
]);
Auth::login($newUser);
return redirect('/home');
}
} catch (Exception $e) {
dd($e->getMessage());
}
}
}
My Google Callback Url
http://localhost:81/auth/google/callback?state=YMuSrsU6925bkwXG59tzHz4Ru8J2VlmOxiG9w5NS&code=4%2F0AY0e-g5f17C96cQZ0CSqtRIOUlq3RcpPj5Y1yp_0ibvDxi_U4S1WOU2QIT_0j7QlfUcabA&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=0&prompt=consent#
Error [1]: https://i.sstatic.net/TNyd6.png
Note: All my routes are correct.
Upvotes: 0
Views: 1951