Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:squint:

Ok so - we shouldn't be utilizing non lifecycle state variables like this i don't think 🤔


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