(Laravel 5.8 with Socialite for Google Login) after register or login system successfully the website won't change to login state, how to check what's wrong?
So, the setup is finished, this is my login controller, was expecting new data for User table but no data, the popup for selecting which gmail account to log in to is shown correctly, how to check what is wrong? how to actually login after selecting a gmail account when pop up shown?
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Socialite;
use App\User;
use Auth;
use Illuminate\Http\Request;
use Hash;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
public function redirectToProvider()
{
return Socialite::driver('google')->redirect();
}
public function handleProviderCallback()
{
try
{
$user = Socialite::driver('google')->user();
}
catch (\Exception $e)
{
return redirect('login');
}
$existingUser = User::where('email', $user->email)->first();
if($existingUser)
{
// log them in
auth()->login($existingUser, true);
}
else
{
// create a new user
$newUser = new User;
$newUser->name = $user->name;
$newUser->email = $user->email;
$newUser->google_id = $user->id;
$newUser->avatar = $user->avatar;
$newUser->avatar_original = $user->avatar_original;
$newUser->save();
auth()->login($newUser, true);
}
return redirect()->to('/');
}
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function login(Request $request)
{
$input = $request->all();
$this->validate($request, [
'email' => 'required|email',
'password' => 'required',
]);
$user = User::where('email', '=', $input['email'])->first();
if(auth()->attempt(array('email' => $input['email'], 'password' => Hash::check($input['password'],$user->password))))
{
// dd('here 1');
if (auth()->user()->is_partner == 1) {
return redirect()->route('partner.home');
}else{
return redirect()->route('home');
}
}
else
{
// dd($input['password']);
return redirect()->route('login')->with('error','Email-Address And Password Are Wrong.');
}
}
}
solved by env parameter..callback url
GOOGLE_REDIRECT=https://yourdomain.com/login/google/callback