public static async Task updateTokenAsync(FirebaseAuthLink res)
        {
            firebase.userLink = res;
            res.RefreshUserDetails().Wait();
            var content = (await res.GetFreshAuthAsync());

            var serilized_content = JsonConvert.SerializeObject(content);

            Preferences.Set("serilizedUser", serilized_content);


            firebase.currentUser = res.User;
            Preferences.Set("email", res.User.Email);
            await firebase.initRealtimeDatabaseAsync(res.FirebaseToken);
        }
Beispiel #2
0
        // TODO: refactor this method and its overload to eliminate duplicate code.
        public async Task <AuthResult> LoginWithEmailAndPasswordAsync(string email,
                                                                      string password,
                                                                      bool enforceValidation = true,
                                                                      bool saveUser          = true)
        {
            ClubUser user = null;

            try
            {
                _auth = await _authProvider.SignInWithEmailAndPasswordAsync(email, password);

                await _auth.RefreshUserDetails();

                user = await UserRepository.FindUserByIdAsync(_auth.User.LocalId);

                if (user == null)
                {
                    user = new ClubUser {
                        Email = email
                    };
                }
                user.UserId          = _auth.User.LocalId;
                user.IsEmailVerified = _auth.User.IsEmailVerified;
                if (!user.IsEmailVerified && enforceValidation)
                {
                    return(new AuthResult {
                        User = user, Result = "Error: Please, validate your email."
                    });
                }
                else
                {
                    if (saveUser)
                    {
                        await UserRepository.SaveUserAsync(user);
                    }
                    CurrentUser = user;
                    return(new AuthResult {
                        User = user, Result = "Success"
                    });
                }
            }
            catch (Exception)
            {
                return(new AuthResult {
                    User = user, Result = "Error: Invalid credentials"
                });
            }
        }