signUpWithGoogle method
Future<void>
signUpWithGoogle(
{ - dynamic onSuccess(
- String
)?,
- dynamic onError(
- dynamic
)?,
})
Implementation
Future<void> signUpWithGoogle({
final Function(String)? onSuccess,
final Function(dynamic)? onError,
}) async {
try {
final _account = await _googleSignIn.signIn();
if (_account == null) throw Exception('No account was selected');
final _tokens = await _account.authentication;
final _cred = GoogleAuthProvider.credential(
idToken: _tokens.idToken,
accessToken: _tokens.accessToken,
);
final _result = await _auth.signInWithCredential(_cred);
final _user = _result.user;
if (_user != null) {
final _userRef = PeamanReferenceHelper.usersCol.doc(_user.uid);
final _userSnap = await _userRef.get();
final _registered = _userSnap.exists;
if (!_registered) {
final _appUser = PeamanUser(
uid: _user.uid,
email: _user.email,
createdAt: _user.metadata.creationTime?.millisecondsSinceEpoch,
);
await AppUserProvider().createUser(user: _appUser);
}
print('Success: Signing up with google');
onSuccess?.call(_user.uid);
}
} catch (e) {
print(e);
print('Error!!!: Signing up with google');
onError?.call(e);
}
}