Hello! I’ve built an application using Meteor user accounts but not accounts UI - doing everything manually.
I’ve got a forgot password link that opens form setup in a modal on the login screen where users can fill out their email address to get password reset instructions. This uses the built in forgotPassword
function which successfully sends the email with the token.
Resetting the password has been simple as well using Accounts.onResetPasswordLink
and then Accounts.resetPassword
. I’ve tested this with a hardcoded newPassword
and it’s worked fine. However, I want to generate a random password, set it, and then send a mail to the user with the new password.
While Accounts.resetPassword
takes the token, changes the password, and logs the user in. The callback runs before the user is logged in so I can’t get any user details and therefore cannot send the new password mail.
// Client
/* On link click in email */
Accounts.onResetPasswordLink(function(token, callback) {
/* Generate password */
function randomString(length, chars) {
let result = '';
for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
const rString = randomString(32, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
/* Send email with new password */
Meteor.call('sendNewPassword', rString, function(err, result) {
/* If no error */
if (!err) {
// Alert user of email and change
Bert.alert('Password changed. Please check your email for your new password.', 'success');
}
});
/* Reset password */
Accounts.resetPassword(token, rString, function(err) {
if (!err) {
console.log('Done');
}
});
});
Any help is appreciated!