accounts-ui
accounts-ui copied to clipboard
How to redirect after password change
I've setup user accounts and added basic pages.
I've made my Profile page with a link to change-password page. When I open it I see:
After changing password I get
I've tried to find any options to redirect user after successful password change, but have no luck. Also I've tried to redirect user manually via History object, but I'm staying on the same page.
Here is my current accounts.ui config:
Accounts.ui.config({
passwordSignupFields: 'EMAIL_ONLY',
loginPath: '/sign-in',
signUpPath: '/sign-up',
resetPasswordPath: '/reset-password',
changePasswordPath: '/change-password',
profilePath: '/profile',
homeRoutePath: '/',
minimumPasswordLength: 6,
});
And React Router 4 routes (RouteLayout is just wrapper function around default Route component)
<RouteLayout layoutProps={{account: true}} path="/sign-in" component={() =>
<div className="container"><Accounts.ui.LoginForm /></div>} />
<RouteLayout layoutProps={{account: true}} path="/sign-up" component={() =>
<div className="container"><Accounts.ui.LoginForm formState={STATES.SIGN_UP} /></div>} />
<RouteLayout layoutProps={{account: true}} path="/change-password" component={() =>
<div className="container"><Accounts.ui.LoginForm formState={STATES.PASSWORD_CHANGE} /></div>} />
<RouteLayout layoutProps={{account: true}} path="/reset-password" component={() =>
<div className="container"><Accounts.ui.LoginForm formState={STATES.PASSWORD_RESET} /></div>} />
I faced the same issue and could not find a solution so I added a redirect (I am using React Router v4) in onSubmitHook
callback :
<Accounts.ui.LoginForm
onSubmitHook={(error, formState) => this.props.history.push('/some-url)}
/>
You can check for formState
in the callback to redirect to different URLs depending if its a login or enroll etc...