Skip to content

Commit

Permalink
nit: Remove authenticators from state (#70365)
Browse files Browse the repository at this point in the history
Remove `authenticators` from state because we only set it once
  • Loading branch information
schew2381 committed May 7, 2024
1 parent 435669b commit 81d3fef
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions static/app/components/superuserStaffAccessForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type Props = {
};

type State = {
authenticators: Array<Authenticator>;
error: boolean;
errorType: string;
isLoading: boolean;
Expand All @@ -40,7 +39,6 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
super(props);
this.authUrl = this.props.hasStaff ? '/staff-auth/' : '/auth/';
this.state = {
authenticators: [],
error: false,
errorType: '',
showAccessForms: true,
Expand All @@ -60,16 +58,17 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
}

const authenticators = await this.getAuthenticators();
this.setState({authenticators: authenticators});
this.authenticators = authenticators;

// Set the error state if there are no authenticators and U2F is on
if (!authenticators.length && !disableU2FForSUForm) {
if (!this.authenticators.length && !disableU2FForSUForm) {
this.handleError(ErrorCodes.NO_AUTHENTICATOR);
}
this.setState({isLoading: false});
}

authUrl: string;
authenticators: Authenticator[] = [];

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

handleSubmit = async data => {
const {api} = this.props;
const {superuserAccessCategory, superuserReason, authenticators} = this.state;
const {superuserAccessCategory, superuserReason} = this.state;
const disableU2FForSUForm = ConfigStore.get('disableU2FForSUForm');

const suAccessCategory = superuserAccessCategory || data.superuserAccessCategory;
const suReason = superuserReason || data.superuserReason;

if (!authenticators.length && !disableU2FForSUForm) {
if (!this.authenticators.length && !disableU2FForSUForm) {
this.handleError(ErrorCodes.NO_AUTHENTICATOR);
return;
}
Expand Down Expand Up @@ -193,7 +192,7 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
}

render() {
const {authenticators, error, errorType, showAccessForms, isLoading} = this.state;
const {error, errorType, showAccessForms, isLoading} = this.state;
if (errorType === ErrorCodes.INVALID_SSO_SESSION) {
this.handleLogout();
return null;
Expand All @@ -212,7 +211,7 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
</StyledAlert>
)}
<U2fContainer
authenticators={authenticators}
authenticators={this.authenticators}
displayMode="sudo"
onTap={this.handleU2fTap}
/>
Expand Down Expand Up @@ -240,7 +239,7 @@ class SuperuserStaffAccessForm extends Component<Props, State> {
{showAccessForms && <Hook name="component:superuser-access-category" />}
{!showAccessForms && (
<U2fContainer
authenticators={authenticators}
authenticators={this.authenticators}
displayMode="sudo"
onTap={this.handleU2fTap}
/>
Expand Down

0 comments on commit 81d3fef

Please sign in to comment.