Adarsh
Adarsh

Reputation: 524

How to cutomise the url sent with Meteor Accounts.ui forgetpassword

I'm using accounts.ui for forget password

Accounts.forgotPassword({email: "[email protected]"}, function (e, r) {
    if (e) {
        console.log(e.reason);
    } else {
        // success
    }
}); 

When I send the email for forget password I simply get below email

enter image description here

Can someone tell me how to simply change the url and send the token with the same token

I tried using below code but that didn't work

main.js(client)

Meteor.startup(() => {
  Accounts.resetPassword.text = function(user, url) {
    url = url.replace('#/', '/');
    console.log("url ==== ", url)
    return `Click this link to reset your password: ${url}`;
  }
});

Upvotes: 0

Views: 126

Answers (2)

akds
akds

Reputation: 681

To change the resetPassword url to a custom one you have to run below code on your server (inside of /server/main.js file).

Accounts.urls.resetPassword = function (token) {
  return FlowRouter.url("/reset-password/:token/", { token });
};

In this case, I am using a FlowRouter to generate that URL but you could technically just return a template literal if you like.

If the above code is in the server main.js file and you run Accounts.forgotPassword() function on the frontend from a localhost, it would generate this link:

http://localhost:3000/reset-password/C9cGfgaLEgGXbCVYJcCLnDYiRi3XJpmt2irLOOaKe56

Upvotes: 0

bordalix
bordalix

Reputation: 432

On the server side:

Accounts.emailTemplates.resetPassword.subject = function () {
  return "Forgot your password?";
};

Accounts.emailTemplates.resetPassword.text = function (user, url) {
  return "Click this link to reset your password:\n\n" + url;
};

Read: https://docs.meteor.com/api/passwords.html#Accounts-emailTemplates

Upvotes: 1

Related Questions