Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
Remove Dedicated Function to Update Password
Browse files Browse the repository at this point in the history
Instead of having a dedicated update password function, we can use the
general update user details to update the password field only.
  • Loading branch information
mainawycliffe committed Aug 8, 2020
1 parent d7db4f7 commit fda70f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
5 changes: 4 additions & 1 deletion cmd/resetPassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ You can provide the password or the user or if left empty, Kamanda will automati
if password == "" {
passwordToSave = utils.PasswordGenerator(10)
}
user, err := auth.UpdateFirebaseUserPassword(context.Background(), v, passwordToSave)
updatePassword := &auth.FirebaseUser{
Password: password,
}
user, err := auth.UpdateFirebaseUser(context.Background(), v, updatePassword)
if err != nil {
hasError = true
utils.StdOutError(os.Stderr, "Error updating user %s password\n", v)
Expand Down
18 changes: 0 additions & 18 deletions firebase/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,6 @@ func NewFirebaseUser(ctx context.Context, user *FirebaseUser) (*auth.UserRecord,
return u, nil
}

// UpdateFirebaseUserPassword update a users password on Firebase Auth.
func UpdateFirebaseUserPassword(ctx context.Context, UID string, password string) (*auth.UserRecord, error) {
params := &auth.UserToUpdate{}
if password == "" {
return nil, fmt.Errorf("Password cannot be empty")
}
params = params.Password(password)
client, err := firebase.Auth(ctx, "", "")
if err != nil {
return nil, fmt.Errorf("Error authenticating firebase account: %w", err)
}
u, err := client.UpdateUser(ctx, UID, params)
if err != nil {
return nil, firebase.NewError(err)
}
return u, nil
}

// UpdateFirebaseUser update a user details on firebase.
func UpdateFirebaseUser(ctx context.Context, UID string, user *FirebaseUser) (*auth.UserRecord, error) {
params := &auth.UserToUpdate{}
Expand Down

0 comments on commit fda70f9

Please sign in to comment.