Skip to content

ref(AccountSecurityEnroll): Re-order methods to make diffs readable #95405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,60 @@ class AccountSecurityEnroll extends DeprecatedAsyncComponent<Props, State> {
return this.state.authenticator?.name ?? 'Authenticator';
}

// Handler when we successfully add a 2fa device
async handleEnrollSuccess() {
// If we're pending approval of an invite, the user will have just joined
// the organization when completing 2fa enrollment. We should reload the
// organization context in that case to assign them to the org.
if (this.pendingInvitation) {
await fetchOrganizationByMember(
this.api,
this.pendingInvitation.memberId.toString(),
{
addOrg: true,
fetchOrgDetails: true,
}
);
}

this.props.router.push('/settings/account/security/');
openRecoveryOptions({authenticatorName: this.authenticatorName});

// The remainder of this function is included primarily to smooth out the relocation flow. The
// newly claimed user will have landed on `https://sentry.io/settings/account/security` to
// perform the 2FA registration. But now that they have in fact registered, we want to redirect
// them to the subdomain of the organization they are already a member of (ex:
// `https://my-2fa-org.sentry.io`), but did not have the ability to access due to their previous
// lack of 2FA enrollment.
let orgs = OrganizationsStore.getAll();
if (orgs.length === 0) {
// Try to load orgs post 2FA again.
orgs = await fetchOrganizations(this.api, {member: '1'});
OrganizationsStore.load(orgs);

// Still no orgs? Nowhere to redirect the user to, so just stay in place.
if (orgs.length === 0) {
return;
}
}

// If we are already in an org sub-domain, we don't need to do any redirection. If we are not
// (this is usually only the case for a newly claimed relocated user), we redirect to the org
// slug's subdomain now.
const isAlreadyInOrgSubDomain = orgs.some(org => {
return org.links.organizationUrl === new URL(window.location.href).origin;
});
if (!isAlreadyInOrgSubDomain) {
testableWindowLocation.assign(generateOrgSlugUrl(orgs[0]!.slug));
}
}

// Handler when we failed to add a 2fa device
handleEnrollError() {
this.setState({loading: false});
addErrorMessage(t('Error adding %s authenticator', this.authenticatorName));
}

// This resets state so that user can re-enter their phone number again
handleSmsReset = () => this.setState({hasSentCode: false}, this.remountComponent);

Expand Down Expand Up @@ -315,60 +369,6 @@ class AccountSecurityEnroll extends DeprecatedAsyncComponent<Props, State> {
}
};

// Handler when we successfully add a 2fa device
async handleEnrollSuccess() {
// If we're pending approval of an invite, the user will have just joined
// the organization when completing 2fa enrollment. We should reload the
// organization context in that case to assign them to the org.
if (this.pendingInvitation) {
await fetchOrganizationByMember(
this.api,
this.pendingInvitation.memberId.toString(),
{
addOrg: true,
fetchOrgDetails: true,
}
);
}

this.props.router.push('/settings/account/security/');
openRecoveryOptions({authenticatorName: this.authenticatorName});

// The remainder of this function is included primarily to smooth out the relocation flow. The
// newly claimed user will have landed on `https://sentry.io/settings/account/security` to
// perform the 2FA registration. But now that they have in fact registered, we want to redirect
// them to the subdomain of the organization they are already a member of (ex:
// `https://my-2fa-org.sentry.io`), but did not have the ability to access due to their previous
// lack of 2FA enrollment.
let orgs = OrganizationsStore.getAll();
if (orgs.length === 0) {
// Try to load orgs post 2FA again.
orgs = await fetchOrganizations(this.api, {member: '1'});
OrganizationsStore.load(orgs);

// Still no orgs? Nowhere to redirect the user to, so just stay in place.
if (orgs.length === 0) {
return;
}
}

// If we are already in an org sub-domain, we don't need to do any redirection. If we are not
// (this is usually only the case for a newly claimed relocated user), we redirect to the org
// slug's subdomain now.
const isAlreadyInOrgSubDomain = orgs.some(org => {
return org.links.organizationUrl === new URL(window.location.href).origin;
});
if (!isAlreadyInOrgSubDomain) {
testableWindowLocation.assign(generateOrgSlugUrl(orgs[0]!.slug));
}
}

// Handler when we failed to add a 2fa device
handleEnrollError() {
this.setState({loading: false});
addErrorMessage(t('Error adding %s authenticator', this.authenticatorName));
}

// Removes an authenticator
handleRemove = async () => {
const {authenticator} = this.state;
Expand Down
Loading