Skip to content

Commit 022b9ee

Browse files
committed
Refactor Google callback handling in SocialAuthController to improve error messaging and user experience
This commit updates the handleGoogleCallback method to store the Google user's email in a variable for better readability. It also adds an error message redirect for users whose email is not found in the database, prompting them to register first. This enhances the overall user experience during the authentication process.
1 parent e048538 commit 022b9ee

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

app/Http/Controllers/Auth/SocialAuthController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ public function handleGoogleCallback(): RedirectResponse
3737
Log::error("Erreur de callback Google: " . $e->getMessage());
3838
return redirect("{$frontendUrl}/login?error=google_auth_failed");
3939
}
40-
41-
$user = User::where('email', $googleUser->getEmail())->first();
40+
$email = $googleUser->getEmail();
41+
$user = User::where('email', $email)->first();
4242

4343
if($user){
4444
if (is_null($user->google_id)) {
4545
$user->google_id = $googleUser->getId();
4646
}
4747
// Mettre à jour d'autres informations si nécessaire
4848
$user->save();
49+
}else{
50+
$errorMsg = urlencode("Cette adresse email ({$email}) n'existe pas dans nos bases de données. Veuillez vous enregistrer d'abord.");
51+
return redirect("{$frontendUrl}/login?code=401");
4952
}
5053

5154
$scope = $this->getUserScope($user->role_id);

0 commit comments

Comments
 (0)