middleware('guest')->except('logout'); } /** * Redirect the user to the Google authentication page. * * @return \Illuminate\Http\Response */ public function redirectToProvider() { return Socialite::driver('google')->redirect(); } /** * Obtain the user information from Google. * * @return \Illuminate\Http\Response */ public function handleProviderCallback() { try { $google_user = Socialite::driver('google')->user(); } catch (Exception $e) { return redirect('/login'); } // only allow people with @company.com to login // if(explode("@", $google_user->email)[1] !== 'upr.edu'){ // return redirect()->to('/'); // } // check if they're in the database $user = \App\User::where('email', $google_user->email)->first(); if($user){ $user->update([ 'name' => $google_user->name, 'email' => $google_user->email, 'google_id' => $google_user->id ]); // dd($user); // log them in auth()->login($user, true); } else { return redirect('/'); } return redirect()->back(); } public function logout(Request $request) { auth()->logout(); return redirect('/'); } }