-
composer.json
Open in GitHub{ // "require": { "php": "^7.3|^8.0", // "laravel/socialite": "^5.0" }, // }
-
app/Http/Controllers/Auth/SocialLoginController.php
Open in GitHubuse App\Providers\RouteServiceProvider; use Auth; use Socialite; class SocialLoginController extends Controller { public function redirectTo() { $redirectTo = request()->redirectTo; if ($redirectTo) { return $redirectTo; } else { return RouteServiceProvider::HOME; } } public function redirectToProvider($provider) { return Socialite::driver($provider)->redirect(); } public function handleProviderCallback($provider) { try { $user = Socialite::driver($provider)->user(); $authUser = $this->findOrCreateUser($user, $provider); Auth::login($authUser, true); } catch (Exception $e) { return redirect('/'); } return redirect()->intended(RouteServiceProvider::HOME); } private function findOrCreateUser($socialUser, $provider) { // } }
-
routes/auth.php
Open in GitHubuse Illuminate\Support\Facades\Route; // Route::group(['namespace' => 'Auth', 'middleware' => 'guest'], function () { Route::get('login/{provider}', ['as' => 'social.login', 'uses' => 'SocialLoginController@redirectToProvider']); Route::get('login/{provider}/callback', 'SocialLoginController@handleProviderCallback'); });
-
resources/views/auth/social_login_buttons.blade.php
Open in GitHub// @if(env('FACEBOOK_ACTIVE')) <a href="{{route('social.login', 'facebook')}}" class="btn btn-neutral btn-icon mb-2"> <span class="btn-inner--icon"> <i class="fab fa-facebook"></i> </span> <span class="btn-inner--text">Facebook</span> </a> @endif //