feat: Implement Google Sign-In functionality and update user profile management
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:google_sign_in_platform_interface/google_sign_in_platform_interface.dart';
|
||||
|
||||
class AuthService {
|
||||
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
|
||||
@@ -64,5 +66,39 @@ class AuthService {
|
||||
// Update the password
|
||||
await currentUser!.updatePassword(newPassword);
|
||||
}
|
||||
|
||||
Future<void> ensureInitialized(){
|
||||
return GoogleSignInPlatform.instance.init(const InitParameters());
|
||||
}
|
||||
|
||||
Future<UserCredential> signInWithGoogle() async {
|
||||
try {
|
||||
await ensureInitialized();
|
||||
final AuthenticationResults result = await GoogleSignInPlatform.instance.authenticate(const AuthenticateParameters());
|
||||
final String? idToken = result.authenticationTokens.idToken;
|
||||
if (idToken == null) {
|
||||
throw FirebaseAuthException(
|
||||
code: 'ERROR_MISSING_GOOGLE_ID_TOKEN',
|
||||
message: 'Missing Google ID Token',
|
||||
);
|
||||
} else {
|
||||
final OAuthCredential credential = GoogleAuthProvider.credential(idToken: idToken);
|
||||
UserCredential userCredential = await firebaseAuth.signInWithCredential(credential);
|
||||
|
||||
// Retourner le UserCredential au lieu de void
|
||||
return userCredential;
|
||||
}
|
||||
|
||||
} on GoogleSignInException catch (e) {
|
||||
print('Erreur lors de l\'initialisation de Google Sign-In: $e');
|
||||
rethrow;
|
||||
} on FirebaseAuthException catch (e) {
|
||||
print('Erreur Firebase lors de l\'initialisation de Google Sign-In: $e');
|
||||
rethrow;
|
||||
} catch (e) {
|
||||
print('Erreur inconnue lors de l\'initialisation de Google Sign-In: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user