autentificacion por celular
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
@@ -14,10 +12,11 @@ class AuthenticationRepository extends GetxController {
|
||||
final _auth = FirebaseAuth.instance;
|
||||
late final Rx<User?> firebaseUser;
|
||||
final GoogleSignIn googleSignIn = GoogleSignIn();
|
||||
var verificationId = ''.obs;
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
Future.delayed(const Duration(seconds: 6));
|
||||
// Future.delayed(const Duration(seconds: 6));
|
||||
firebaseUser = Rx<User?>(_auth.currentUser);
|
||||
firebaseUser.bindStream(_auth.userChanges());
|
||||
ever(firebaseUser, _setInitialScreen);
|
||||
@@ -29,6 +28,35 @@ class AuthenticationRepository extends GetxController {
|
||||
: Get.offAll(() => const WelcomeScreen());
|
||||
}
|
||||
|
||||
Future<void> phoneAuthentication(String phoneNo) async {
|
||||
await _auth.verifyPhoneNumber(
|
||||
phoneNumber: phoneNo,
|
||||
verificationCompleted: (credential) async {
|
||||
await _auth.signInWithCredential(credential);
|
||||
},
|
||||
codeSent: (verificationId, resendToken) {
|
||||
this.verificationId.value = verificationId;
|
||||
},
|
||||
codeAutoRetrievalTimeout: (verificationId) {
|
||||
this.verificationId.value = verificationId;
|
||||
},
|
||||
verificationFailed: (e) {
|
||||
if (e.code == 'invalid-phone-number') {
|
||||
Get.snackbar('Error', 'El numero no es valido.');
|
||||
} else {
|
||||
Get.snackbar('Error', 'Algo ha ido mal. Inténtalo de nuevo. $e');
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> verifyOTP(String otp) async {
|
||||
var credentials = await _auth.signInWithCredential(
|
||||
PhoneAuthProvider.credential(
|
||||
verificationId: verificationId.value, smsCode: otp));
|
||||
return credentials.user != null ? true : false;
|
||||
}
|
||||
|
||||
Future<void> createUserWithEmailAndPassword(
|
||||
String email, String password) async {
|
||||
try {
|
||||
@@ -54,17 +82,20 @@ class AuthenticationRepository extends GetxController {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<UserCredential> signInWithGoogle() async {
|
||||
final GoogleSignInAccount? googleSignInAccount =
|
||||
await googleSignIn.signIn();
|
||||
final GoogleSignInAuthentication googleSignInAuthentication =
|
||||
await googleSignInAccount!.authentication;
|
||||
|
||||
final AuthCredential credential = GoogleAuthProvider.credential(
|
||||
accessToken: googleSignInAuthentication.accessToken,
|
||||
idToken: googleSignInAuthentication.idToken,
|
||||
);
|
||||
|
||||
return await _auth.signInWithCredential(credential);
|
||||
Future<void> signInWithGoogle() async {
|
||||
try {
|
||||
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
|
||||
final GoogleSignInAuthentication googleAuth =
|
||||
await googleUser!.authentication;
|
||||
final credential = GoogleAuthProvider.credential(
|
||||
accessToken: googleAuth.accessToken,
|
||||
idToken: googleAuth.idToken,
|
||||
);
|
||||
await FirebaseAuth.instance.signInWithCredential(credential);
|
||||
} catch (e) {
|
||||
print('Error - ${e}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> logout() async => _auth.signOut();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user