Reputation: 429
I want to implement change email functionality for my application built on Meteor.js
The flow would be:
1.User would request for change email via "Change Email" form.
<div class="settings-container">
<div class="container-header medium-margin-top bold">Change Email</div>
<div class="container-inner less-margin-top">
<form>
<div>
<dl>
<dt><label for="user_email_address">Email Address</label></dt>
<dd><input type="email" class="form-control" id="new-email"></dd>
</dl>
</div>
<button type="submit" id="btn-change-email" class="btn btn-success">Send Verification Link</button>
</form>
</div>
</div>
2.The forms sends a verification email using Accounts.sendVerificationEmail
I created a method for the same which is called when the verification mail needs to be sent
change_email: function(userId, email) {
Accounts.sendVerificationEmail(userId, email);
},
3.The email address should change once the user verifies the new email address.
I am unable to think of a proper solution for step three. I thought of using Accounts.verifyEmail but could not think out a way to change the email address.
Upvotes: 1
Views: 460
Reputation: 688
Seems like you're going about it backwards. You should first add the new email to the Meteor.user.emails
array, or replace the existing entry if you really want to update rather than use the built-in support for multiple email addresses. Then you can send the verification email.
Upvotes: 2