meteorpasswordsmeteor-autoform

Password update with Meteor Autoforms


I'm trying to make an account page where the user can update their profile info and/or update their password. I'm currently using this for the form:

{{#autoForm collection="Meteor.users" doc=profile id="myAccount" type="update"}}
                        <fieldset>
                            <legend>My Account</legend>
                            {{> afQuickField name="username"}}
                            {{> afQuickField name="profile.firstName"}}
                            {{> afQuickField name="profile.lastName"}}
                            {{> afQuickField name="emails.0.address"}}
                            {{> afQuickField name="emails.0.verified" class="i-checks"}}
                            {{> afQuickField name="password"}}
                        </fieldset>
                        <button type="submit" class="btn btn-primary">Update</button>
                    {{/autoForm}}

From what I understand, I need to user Accounts.setPassword in order to update a users password. So I figured I'd have to use a hook for this, but the onSubmit hook doesn't work with the type update.

What's the best way to update a password with this kind of form?


Solution

  • Will something like this work: https://github.com/aldeed/meteor-autoform#normal where contact form is the name of your form?

    AutoForm.hooks({
      contactForm: {
        onSubmit: function (insertDoc, updateDoc, currentDoc) {
          if (customHandler(insertDoc)) {
            this.done();
          } else {
            this.done(new Error("Submission failed"));
          }
          return false;
        }
      }
    });