'Cancel' link in Change Password view does not use config.loginPath
I have routes for /change-password and /login (using React Router), which render Accounts.ui.LoginForm.
// config
Accounts.ui.config({
changePasswordPath: '/change-password',
loginPath: '/login'
// ...
});
On the Change Password view, clicking 'Cancel' correctly changes the form fields to the login state, but does not update the route URL. Probably related to #83
Temporary workaround:
Extend Accounts.ui.LoginForm and supply a new buttons() method:
class LoginForm extends Accounts.ui.LoginForm {
buttons () {
const buttons = super.buttons();
const {loginPath} = Accounts.ui._options;
if (loginPath && 'cancelResetPassword' in buttons) {
buttons.cancelResetPassword.href = loginPath;
}
return buttons;
}
}
Accounts.ui.LoginForm = LoginForm;
@premasagar Thank you for the workaround, I was able to get to a good enough solution thanks to it. However unlike you, I wasn't able to make the cancel button work by setting the href property. Instead, I overwrote the onClick callback to redirect to where I wanted.
Here's an example. I am able to access history by using the withHistory HOC from React-Router@4.
import { Accounts } from 'meteor/std:accounts-ui';
import { withRouter } from 'react-router';
class LoginForm extends Accounts.ui.LoginForm {
buttons () {
const buttons = super.buttons();
const { loginPath } = Accounts.ui._options;
const { history } = this.props;
if (loginPath && 'cancelResetPassword' in buttons) {
buttons.cancelResetPassword.onClick = () => history.push(loginPath);
}
return buttons;
}
}
export default withRouter(LoginForm);