mirror of
https://github.com/vale981/accounts-ui
synced 2025-03-05 09:51:40 -05:00
Merge pull request #94 from xavcz/master
Better support for Server-Side Rendering & client-only code in React client-only lifecycle hook
This commit is contained in:
commit
79781e2439
1 changed files with 34 additions and 29 deletions
|
@ -44,46 +44,51 @@ export class LoginForm extends Tracker.Component {
|
||||||
onSignedOutHook: props.onSignedOutHook || Accounts.ui._options.onSignedOutHook,
|
onSignedOutHook: props.onSignedOutHook || Accounts.ui._options.onSignedOutHook,
|
||||||
onPreSignUpHook: props.onPreSignUpHook || Accounts.ui._options.onPreSignUpHook,
|
onPreSignUpHook: props.onPreSignUpHook || Accounts.ui._options.onPreSignUpHook,
|
||||||
onPostSignUpHook: props.onPostSignUpHook || Accounts.ui._options.onPostSignUpHook,
|
onPostSignUpHook: props.onPostSignUpHook || Accounts.ui._options.onPostSignUpHook,
|
||||||
// Add default field values.
|
|
||||||
...this.getDefaultFieldValues(),
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.setState(prevState => ({ waiting: false, ready: true }));
|
||||||
|
let changeState = Session.get(KEY_PREFIX + 'state');
|
||||||
|
switch (changeState) {
|
||||||
|
case 'enrollAccountToken':
|
||||||
|
this.setState(prevState => ({
|
||||||
|
formState: STATES.ENROLL_ACCOUNT
|
||||||
|
}));
|
||||||
|
Session.set(KEY_PREFIX + 'state', null);
|
||||||
|
break;
|
||||||
|
case 'resetPasswordToken':
|
||||||
|
this.setState(prevState => ({
|
||||||
|
formState: STATES.PASSWORD_CHANGE
|
||||||
|
}));
|
||||||
|
Session.set(KEY_PREFIX + 'state', null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'justVerifiedEmail':
|
||||||
|
this.setState(prevState => ({
|
||||||
|
formState: STATES.PROFILE
|
||||||
|
}));
|
||||||
|
Session.set(KEY_PREFIX + 'state', null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add default field values once the form did mount on the client
|
||||||
|
this.setState(prevState => ({
|
||||||
|
...this.getDefaultFieldValues(),
|
||||||
|
}));
|
||||||
|
|
||||||
// Listen for the user to login/logout.
|
// Listen for the user to login/logout.
|
||||||
this.autorun(() => {
|
this.autorun(() => {
|
||||||
|
|
||||||
// Add the services list to the user.
|
// Add the services list to the user.
|
||||||
this.subscribe('servicesList');
|
this.subscribe('servicesList');
|
||||||
this.setState({
|
this.setState({
|
||||||
user: Accounts.user()
|
user: Accounts.user()
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.setState({ waiting: false, ready: true });
|
|
||||||
let changeState = Session.get(KEY_PREFIX + 'state');
|
|
||||||
switch (changeState) {
|
|
||||||
case 'enrollAccountToken':
|
|
||||||
this.setState({
|
|
||||||
formState: STATES.ENROLL_ACCOUNT
|
|
||||||
});
|
|
||||||
Session.set(KEY_PREFIX + 'state', null);
|
|
||||||
break;
|
|
||||||
case 'resetPasswordToken':
|
|
||||||
this.setState({
|
|
||||||
formState: STATES.PASSWORD_CHANGE
|
|
||||||
});
|
|
||||||
Session.set(KEY_PREFIX + 'state', null);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'justVerifiedEmail':
|
|
||||||
this.setState({
|
|
||||||
formState: STATES.PROFILE
|
|
||||||
});
|
|
||||||
Session.set(KEY_PREFIX + 'state', null);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps, nextContext) {
|
componentWillReceiveProps(nextProps, nextContext) {
|
||||||
if (nextProps.formState && nextProps.formState !== this.state.formState) {
|
if (nextProps.formState && nextProps.formState !== this.state.formState) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -992,6 +997,6 @@ export class LoginForm extends Tracker.Component {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
Accounts.ui.LoginForm = LoginForm;
|
Accounts.ui.LoginForm = LoginForm;
|
||||||
|
|
Loading…
Add table
Reference in a new issue