Login Googgle (Verificar que exista en la lista de confianza)
This commit is contained in:
parent
80637327ee
commit
1d342997ca
@ -31,14 +31,12 @@ public function handleProviderCallback($provider){
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$userProvider = Socialite::driver($provider) ->stateless()->user();
|
$userProvider = Socialite::driver($provider) ->stateless()->user();
|
||||||
error_log(json_encode($userProvider->user));
|
|
||||||
}
|
}
|
||||||
catch (ClientException $exception) {
|
catch (ClientException $exception) {
|
||||||
return response()->json(['error' => 'Credenciales de google invalidas.'],422);
|
return response()->json(['error' => 'Credenciales de google invalidas.'],422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset(User::where("email","=", $userProvider->email)->first()){
|
||||||
|
|
||||||
$userCreated = User::firstOrCreate(
|
$userCreated = User::firstOrCreate(
|
||||||
[
|
[
|
||||||
'email' => $userProvider->email
|
'email' => $userProvider->email
|
||||||
@ -66,9 +64,16 @@ public function handleProviderCallback($provider){
|
|||||||
"message" => "Usuario logueado",
|
"message" => "Usuario logueado",
|
||||||
"user" => $userCreated,
|
"user" => $userCreated,
|
||||||
"image" => $userProvider->getAvatar(),
|
"image" => $userProvider->getAvatar(),
|
||||||
|
"role" => $userCreated->roles[0]->name,
|
||||||
"access_token" => $token
|
"access_token" => $token
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return response()->json([
|
||||||
|
"status" => 0,
|
||||||
|
"message" => "Usuario no registrado en el sistema",
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user