@@ -201,6 +201,60 @@ class AccountSecurityEnroll extends DeprecatedAsyncComponent<Props, State> {
201
201
return this . state . authenticator ?. name ?? 'Authenticator' ;
202
202
}
203
203
204
+ // Handler when we successfully add a 2fa device
205
+ async handleEnrollSuccess ( ) {
206
+ // If we're pending approval of an invite, the user will have just joined
207
+ // the organization when completing 2fa enrollment. We should reload the
208
+ // organization context in that case to assign them to the org.
209
+ if ( this . pendingInvitation ) {
210
+ await fetchOrganizationByMember (
211
+ this . api ,
212
+ this . pendingInvitation . memberId . toString ( ) ,
213
+ {
214
+ addOrg : true ,
215
+ fetchOrgDetails : true ,
216
+ }
217
+ ) ;
218
+ }
219
+
220
+ this . props . router . push ( '/settings/account/security/' ) ;
221
+ openRecoveryOptions ( { authenticatorName : this . authenticatorName } ) ;
222
+
223
+ // The remainder of this function is included primarily to smooth out the relocation flow. The
224
+ // newly claimed user will have landed on `https://sentry.io/settings/account/security` to
225
+ // perform the 2FA registration. But now that they have in fact registered, we want to redirect
226
+ // them to the subdomain of the organization they are already a member of (ex:
227
+ // `https://my-2fa-org.sentry.io`), but did not have the ability to access due to their previous
228
+ // lack of 2FA enrollment.
229
+ let orgs = OrganizationsStore . getAll ( ) ;
230
+ if ( orgs . length === 0 ) {
231
+ // Try to load orgs post 2FA again.
232
+ orgs = await fetchOrganizations ( this . api , { member : '1' } ) ;
233
+ OrganizationsStore . load ( orgs ) ;
234
+
235
+ // Still no orgs? Nowhere to redirect the user to, so just stay in place.
236
+ if ( orgs . length === 0 ) {
237
+ return ;
238
+ }
239
+ }
240
+
241
+ // If we are already in an org sub-domain, we don't need to do any redirection. If we are not
242
+ // (this is usually only the case for a newly claimed relocated user), we redirect to the org
243
+ // slug's subdomain now.
244
+ const isAlreadyInOrgSubDomain = orgs . some ( org => {
245
+ return org . links . organizationUrl === new URL ( window . location . href ) . origin ;
246
+ } ) ;
247
+ if ( ! isAlreadyInOrgSubDomain ) {
248
+ testableWindowLocation . assign ( generateOrgSlugUrl ( orgs [ 0 ] ! . slug ) ) ;
249
+ }
250
+ }
251
+
252
+ // Handler when we failed to add a 2fa device
253
+ handleEnrollError ( ) {
254
+ this . setState ( { loading : false } ) ;
255
+ addErrorMessage ( t ( 'Error adding %s authenticator' , this . authenticatorName ) ) ;
256
+ }
257
+
204
258
// This resets state so that user can re-enter their phone number again
205
259
handleSmsReset = ( ) => this . setState ( { hasSentCode : false } , this . remountComponent ) ;
206
260
@@ -315,60 +369,6 @@ class AccountSecurityEnroll extends DeprecatedAsyncComponent<Props, State> {
315
369
}
316
370
} ;
317
371
318
- // Handler when we successfully add a 2fa device
319
- async handleEnrollSuccess ( ) {
320
- // If we're pending approval of an invite, the user will have just joined
321
- // the organization when completing 2fa enrollment. We should reload the
322
- // organization context in that case to assign them to the org.
323
- if ( this . pendingInvitation ) {
324
- await fetchOrganizationByMember (
325
- this . api ,
326
- this . pendingInvitation . memberId . toString ( ) ,
327
- {
328
- addOrg : true ,
329
- fetchOrgDetails : true ,
330
- }
331
- ) ;
332
- }
333
-
334
- this . props . router . push ( '/settings/account/security/' ) ;
335
- openRecoveryOptions ( { authenticatorName : this . authenticatorName } ) ;
336
-
337
- // The remainder of this function is included primarily to smooth out the relocation flow. The
338
- // newly claimed user will have landed on `https://sentry.io/settings/account/security` to
339
- // perform the 2FA registration. But now that they have in fact registered, we want to redirect
340
- // them to the subdomain of the organization they are already a member of (ex:
341
- // `https://my-2fa-org.sentry.io`), but did not have the ability to access due to their previous
342
- // lack of 2FA enrollment.
343
- let orgs = OrganizationsStore . getAll ( ) ;
344
- if ( orgs . length === 0 ) {
345
- // Try to load orgs post 2FA again.
346
- orgs = await fetchOrganizations ( this . api , { member : '1' } ) ;
347
- OrganizationsStore . load ( orgs ) ;
348
-
349
- // Still no orgs? Nowhere to redirect the user to, so just stay in place.
350
- if ( orgs . length === 0 ) {
351
- return ;
352
- }
353
- }
354
-
355
- // If we are already in an org sub-domain, we don't need to do any redirection. If we are not
356
- // (this is usually only the case for a newly claimed relocated user), we redirect to the org
357
- // slug's subdomain now.
358
- const isAlreadyInOrgSubDomain = orgs . some ( org => {
359
- return org . links . organizationUrl === new URL ( window . location . href ) . origin ;
360
- } ) ;
361
- if ( ! isAlreadyInOrgSubDomain ) {
362
- testableWindowLocation . assign ( generateOrgSlugUrl ( orgs [ 0 ] ! . slug ) ) ;
363
- }
364
- }
365
-
366
- // Handler when we failed to add a 2fa device
367
- handleEnrollError ( ) {
368
- this . setState ( { loading : false } ) ;
369
- addErrorMessage ( t ( 'Error adding %s authenticator' , this . authenticatorName ) ) ;
370
- }
371
-
372
372
// Removes an authenticator
373
373
handleRemove = async ( ) => {
374
374
const { authenticator} = this . state ;
0 commit comments