Skip to content

Commit 0c1e994

Browse files
committed
fix(aws-amplify-react): change to forgetpassword state if need to reset password
1 parent fe4540a commit 0c1e994

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

packages/aws-amplify-react/src/Auth/AuthPiece.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export default class AuthPiece extends Component {
8181
render() {
8282
if (!this._validAuthStates.includes(this.props.authState)) {
8383
this._isHidden = true;
84+
this.inputs = {};
8485
return null;
8586
}
8687

packages/aws-amplify-react/src/Auth/ForgotPassword.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export default class ForgotPassword extends AuthPiece {
4747
}
4848

4949
send() {
50-
const { username } = this.inputs;
50+
const { authData={} } = this.props;
51+
const username = this.inputs.username || authData.username;
5152
if (!Auth || typeof Auth.forgotPassword !== 'function') {
5253
throw new Error('No Auth module found, please ensure @aws-amplify/auth is imported');
5354
}
@@ -60,7 +61,10 @@ export default class ForgotPassword extends AuthPiece {
6061
}
6162

6263
submit() {
63-
const { username, code, password } = this.inputs;
64+
const { authData={} } = this.props;
65+
const { code, password } = this.inputs;
66+
const username = this.inputs.username || authData.username;
67+
6468
if (!Auth || typeof Auth.forgotPasswordSubmit !== 'function') {
6569
throw new Error('No Auth module found, please ensure @aws-amplify/auth is imported');
6670
}
@@ -117,24 +121,24 @@ export default class ForgotPassword extends AuthPiece {
117121
}
118122

119123
showComponent(theme) {
120-
const { authState, hide } = this.props;
124+
const { authState, hide, authData={} } = this.props;
121125
if (hide && hide.includes(ForgotPassword)) { return null; }
122126

123127
return (
124128
<FormSection theme={theme}>
125129
<SectionHeader theme={theme}>{I18n.get('Reset your password')}</SectionHeader>
126130
<SectionBody>
127-
{ this.state.delivery? this.submitView() : this.sendView() }
131+
{ this.state.delivery || authData.username ? this.submitView() : this.sendView() }
128132
</SectionBody>
129133
<SectionFooter theme={theme}>
130134
<SectionFooterPrimaryContent theme={theme}>
131-
{ this.state.delivery ?
135+
{ this.state.delivery || authData.username ?
132136
<Button theme={theme} onClick={this.submit}>{I18n.get('Submit')}</Button> :
133137
<Button theme={theme} onClick={this.send}>{I18n.get('Send Code')}</Button>
134138
}
135139
</SectionFooterPrimaryContent>
136140
<SectionFooterSecondaryContent theme={theme}>
137-
{ this.state.delivery ?
141+
{ this.state.delivery || authData.username ?
138142
<Link theme={theme} onClick={this.send}>{I18n.get('Resend Code')}</Link> :
139143
<Link theme={theme} onClick={() => this.changeState('signIn')}>{I18n.get('Back to Sign In')}</Link>
140144
}

packages/aws-amplify-react/src/Auth/SignIn.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default class SignIn extends AuthPiece {
108108
}
109109
else if (err.code === 'PasswordResetRequiredException') {
110110
logger.debug('the user requires a new password');
111-
this.changeState('requireNewPassword', { username });
111+
this.changeState('forgotPassword', { username });
112112
} else {
113113
this.error(err);
114114
}

0 commit comments

Comments
 (0)