Skip to content

Commit 81d3fef

Browse files
authored
nit: Remove authenticators from state (#70365)
Remove `authenticators` from state because we only set it once
1 parent 435669b commit 81d3fef

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

static/app/components/superuserStaffAccessForm.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type Props = {
2626
};
2727

2828
type State = {
29-
authenticators: Array<Authenticator>;
3029
error: boolean;
3130
errorType: string;
3231
isLoading: boolean;
@@ -40,7 +39,6 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
4039
super(props);
4140
this.authUrl = this.props.hasStaff ? '/staff-auth/' : '/auth/';
4241
this.state = {
43-
authenticators: [],
4442
error: false,
4543
errorType: '',
4644
showAccessForms: true,
@@ -60,16 +58,17 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
6058
}
6159

6260
const authenticators = await this.getAuthenticators();
63-
this.setState({authenticators: authenticators});
61+
this.authenticators = authenticators;
6462

6563
// Set the error state if there are no authenticators and U2F is on
66-
if (!authenticators.length && !disableU2FForSUForm) {
64+
if (!this.authenticators.length && !disableU2FForSUForm) {
6765
this.handleError(ErrorCodes.NO_AUTHENTICATOR);
6866
}
6967
this.setState({isLoading: false});
7068
}
7169

7270
authUrl: string;
71+
authenticators: Authenticator[] = [];
7372

7473
handleSubmitCOPS = () => {
7574
this.setState({
@@ -80,13 +79,13 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
8079

8180
handleSubmit = async data => {
8281
const {api} = this.props;
83-
const {superuserAccessCategory, superuserReason, authenticators} = this.state;
82+
const {superuserAccessCategory, superuserReason} = this.state;
8483
const disableU2FForSUForm = ConfigStore.get('disableU2FForSUForm');
8584

8685
const suAccessCategory = superuserAccessCategory || data.superuserAccessCategory;
8786
const suReason = superuserReason || data.superuserReason;
8887

89-
if (!authenticators.length && !disableU2FForSUForm) {
88+
if (!this.authenticators.length && !disableU2FForSUForm) {
9089
this.handleError(ErrorCodes.NO_AUTHENTICATOR);
9190
return;
9291
}
@@ -193,7 +192,7 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
193192
}
194193

195194
render() {
196-
const {authenticators, error, errorType, showAccessForms, isLoading} = this.state;
195+
const {error, errorType, showAccessForms, isLoading} = this.state;
197196
if (errorType === ErrorCodes.INVALID_SSO_SESSION) {
198197
this.handleLogout();
199198
return null;
@@ -212,7 +211,7 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
212211
</StyledAlert>
213212
)}
214213
<U2fContainer
215-
authenticators={authenticators}
214+
authenticators={this.authenticators}
216215
displayMode="sudo"
217216
onTap={this.handleU2fTap}
218217
/>
@@ -240,7 +239,7 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
240239
{showAccessForms && <Hook name="component:superuser-access-category" />}
241240
{!showAccessForms && (
242241
<U2fContainer
243-
authenticators={authenticators}
242+
authenticators={this.authenticators}
244243
displayMode="sudo"
245244
onTap={this.handleU2fTap}
246245
/>

0 commit comments

Comments
 (0)