public PhoneAuthPhoneNumberEntryViewModel( AuthAction authAction, IObservable <Unit> whenVerified, IFirebaseAuthService firebaseAuthService = null, IViewStackService viewStackService = null) : base(viewStackService) { _firebaseAuthService = firebaseAuthService ?? Locator.Current.GetService <IFirebaseAuthService>(); var canExecute = this.WhenAnyValue( vm => vm.PhoneNumber, phoneNumber => { return(!string.IsNullOrEmpty(phoneNumber)); }); VerifyPhoneNumber = ReactiveCommand.CreateFromObservable( () => { if (authAction == AuthAction.SignIn) { return(_firebaseAuthService .SignInWithPhoneNumber(_phoneNumber) .SelectMany(result => HandleResult(authAction, result, whenVerified))); } else { return(_firebaseAuthService.CurrentUser .LinkWithPhoneNumber(PhoneNumberTest) .SelectMany(result => HandleResult(authAction, result, whenVerified))); } }, canExecute); VerifyPhoneNumber.ThrownExceptions .Subscribe( ex => { if (ex is FirebaseAuthException firebaseEx) { switch (firebaseEx.FirebaseAuthExceptionType) { case FirebaseAuthExceptionType.FirebaseAuth: Console.WriteLine(firebaseEx.Message); break; case FirebaseAuthExceptionType.FirebaseAuthInvalidCredentials: Console.WriteLine(firebaseEx.Message); break; } Console.WriteLine(firebaseEx.Message); } else { Console.WriteLine(ex.Message); } }); }
public PhoneAuthVerificationCodeEntryViewModel( AuthAction authAction, string verificationId, IObservable <Unit> whenVerified, IFirebaseAuthService firebaseAuthService = null, IViewStackService viewStackService = null) : base(viewStackService) { _firebaseAuthService = firebaseAuthService ?? Locator.Current.GetService <IFirebaseAuthService>(); var canExecute = this.WhenAnyValue(vm => vm.VerificationCode, code => code != null && code.Length == REQUIRED_CODE_LENGTH); VerifyCode = ReactiveCommand.CreateFromObservable( () => { if (authAction == AuthAction.SignIn) { return(_firebaseAuthService .SignInWithPhoneNumber(verificationId, VerificationCode) .SelectMany(_ => whenVerified)); } else { return(_firebaseAuthService.CurrentUser .LinkWithPhoneNumber(verificationId, VerificationCode) .ObserveOn(RxApp.MainThreadScheduler) .SelectMany(_ => whenVerified)); } }, canExecute); VerifyCode.ThrownExceptions .Subscribe( ex => { Console.WriteLine(ex.Message); }); }