@@ -44,33 +44,11 @@ export default function (server: Server, ctx: AppContext) {
44
44
const now = new Date ( ) . toISOString ( )
45
45
const passwordScrypt = await scrypt . genSaltAndHash ( password )
46
46
47
- let verificationPhone : string | undefined = undefined
48
- if ( ctx . cfg . phoneVerification . required && ctx . twilio ) {
49
- if ( ! input . body . verificationPhone ) {
50
- throw new InvalidRequestError (
51
- `Text verification is now required on this server. Please make sure you're using the latest version of the Bluesky app.` ,
52
- 'InvalidPhoneVerification' ,
53
- )
54
- } else if ( ! input . body . verificationCode ) {
55
- throw new InvalidRequestError (
56
- `Text verification is now required on this server. Please make sure you're using the latest version of the Bluesky app.` ,
57
- 'InvalidPhoneVerification' ,
58
- )
59
- }
60
- verificationPhone = ctx . twilio . normalizePhoneNumber (
61
- input . body . verificationPhone ,
62
- )
63
- const verified = await ctx . twilio . verifyCode (
64
- verificationPhone ,
65
- input . body . verificationCode . trim ( ) ,
66
- )
67
- if ( ! verified ) {
68
- throw new InvalidRequestError (
69
- 'Could not verify phone number. Please try again.' ,
70
- 'InvalidPhoneVerification' ,
71
- )
72
- }
73
- }
47
+ const verificationPhone = await ensurePhoneVerification (
48
+ ctx ,
49
+ input . body . verificationPhone ,
50
+ input . body . verificationCode ?. trim ( ) ,
51
+ )
74
52
75
53
const result = await ctx . db . transaction ( async ( dbTxn ) => {
76
54
const actorTxn = ctx . services . account ( dbTxn )
@@ -491,6 +469,42 @@ const ensureUnusedHandleAndEmail = async (
491
469
}
492
470
}
493
471
472
+ const ensurePhoneVerification = async (
473
+ ctx : AppContext ,
474
+ phone ?: string ,
475
+ code ?: string ,
476
+ ) : Promise < string | undefined > => {
477
+ if ( ! ctx . cfg . phoneVerification . required || ! ctx . twilio ) {
478
+ return
479
+ }
480
+
481
+ if ( ! phone ) {
482
+ throw new InvalidRequestError (
483
+ `Text verification is now required on this server. Please make sure you're using the latest version of the Bluesky app.` ,
484
+ 'InvalidPhoneVerification' ,
485
+ )
486
+ }
487
+ if ( ctx . cfg . phoneVerification . bypassPhoneNumber === phone ) {
488
+ return undefined
489
+ }
490
+
491
+ if ( ! code ) {
492
+ throw new InvalidRequestError (
493
+ `Text verification is now required on this server. Please make sure you're using the latest version of the Bluesky app.` ,
494
+ 'InvalidPhoneVerification' ,
495
+ )
496
+ }
497
+ const normalizedPhone = ctx . twilio . normalizePhoneNumber ( phone )
498
+ const verified = await ctx . twilio . verifyCode ( normalizedPhone , code )
499
+ if ( ! verified ) {
500
+ throw new InvalidRequestError (
501
+ 'Could not verify phone number. Please try again.' ,
502
+ 'InvalidPhoneVerification' ,
503
+ )
504
+ }
505
+ return normalizedPhone
506
+ }
507
+
494
508
const randomIndexByWeight = ( weights ) => {
495
509
let sum = 0
496
510
const cumulative = weights . map ( ( weight ) => {
0 commit comments