accounts-ui icon indicating copy to clipboard operation
accounts-ui copied to clipboard

How to redirect after password change

Open kolyasya opened this issue 7 years ago • 1 comments

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:

image

After changing password I get

image

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>} />

kolyasya avatar Apr 18 '17 12:04 kolyasya

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...

capi1O avatar Nov 20 '18 08:11 capi1O