Last active
October 2, 2017 02:44
-
-
Save rslhdyt/cfdee2f3645691e8c2ce92927fcfb876 to your computer and use it in GitHub Desktop.
Socialite Callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Auth; | |
use App\Http\Controllers\Controller; | |
use App\Models\User; | |
use Auth; | |
use Illuminate\Http\Request; | |
use Socialite; | |
class LoginProviderController extends Controller | |
{ | |
public function login() | |
{ | |
return Socialite::driver('koperasi_io')->redirect(); | |
} | |
public function callback() | |
{ | |
// get user detail from facebook | |
$userProvider = Socialite::driver('facebook')->user(); | |
$user = User::firstOrCreate([ | |
'email' => $userProvider->email, | |
], [ | |
'name' => $userProvider->user['name'], | |
'provider_id' => $userProvider->getId(), | |
'email' => $userProvider->user['email'], | |
'token' => $userProvider->token, | |
]); | |
// add more logic here, like send email and etc | |
// perform login using user id | |
Auth::loginUsingId($user->id); | |
// finaly, redirect to specific route | |
return redirect()->route('home')->with('message_info', __('notifications.welcome', ['name' => $user->name])); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment