private async Task ResolveAsync(FirebaseAuthException firebaseAuthException) { if (firebaseAuthException.Resolver == null) { System.Diagnostics.Debug.WriteLine(firebaseAuthException); await _pageDialogService.DisplayAlertAsync("Failure", firebaseAuthException.Message, "OK"); } else { try { var result = await _multiFactorService.ResolveAsync(firebaseAuthException.Resolver); await _pageDialogService.DisplayAlertAsync("Success", result.User.DisplayName, "OK"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); await _pageDialogService.DisplayAlertAsync("Failure", ex.Message, "OK"); } } }
public SignInWithEmailAndPasswordPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService) : base(navigationService) { _pageDialogService = pageDialogService; _multiFactorService = new MultiFactorService(this); Title = "Sign In "; SignInCommand = new[] { Email.Select(s => string.IsNullOrEmpty(s)), Password.Select(s => string.IsNullOrEmpty(s)) }.CombineLatest(x => x.All(y => !y)) .ToAsyncReactiveCommand(); SignInCommand.Subscribe(async() => { try { var result = await CrossFirebaseAuth.Current .Instance .SignInWithEmailAndPasswordAsync(Email.Value, Password.Value); await NavigationService.GoBackAsync(result.User); } catch (FirebaseAuthException e) { if (e.Resolver == null) { System.Diagnostics.Debug.WriteLine(e); await _pageDialogService.DisplayAlertAsync("Failure", e.Message, "OK"); } else { try { var result = await _multiFactorService.ResolveAsync(e.Resolver); await _pageDialogService.DisplayAlertAsync("Success", result.User.DisplayName, "OK"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); await _pageDialogService.DisplayAlertAsync("Failure", ex.Message, "OK"); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); await _pageDialogService.DisplayAlertAsync("Failure", e.Message, "OK"); } }); ResetPasswordCommand = new[] { Email.Select(s => string.IsNullOrEmpty(s)), }.CombineLatest(x => x.All(y => !y)) .ToAsyncReactiveCommand(); ResetPasswordCommand.Subscribe(async() => { try { await CrossFirebaseAuth.Current .Instance .SendPasswordResetEmailAsync(Email.Value); await _pageDialogService.DisplayAlertAsync(null, "Email has been sent.", "OK"); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); await _pageDialogService.DisplayAlertAsync("Failure", e.Message, "OK"); } }); }