Skip to content

Commit c5b64d1

Browse files
committed
Introduce urrentVerifyFlow to clarify verification logic
1 parent 1874b01 commit c5b64d1

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

src/app/auth/components/verify/verify.component.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,19 @@ describe('VerifyComponent', () => {
236236
expect(component.captchaPassed).toBeTruthy();
237237
expect(component.canSendCodes('phone')).toBeTruthy();
238238
});
239+
240+
it('should set flow to email when only email is unverified', async () => {
241+
await init(defaultAuthData, { sendEmail: true });
242+
243+
expect(component.currentVerifyFlow).toBe('email');
244+
expect(component.formTitle).toBe('Verify Email');
245+
});
246+
247+
it('should set flow to phone when only phone is unverified', async () => {
248+
const unverifiedPhoneData = require('@root/test/responses/auth.verify.unverifiedPhone.success.json');
249+
await init(unverifiedPhoneData, { sendSms: true });
250+
251+
expect(component.currentVerifyFlow).toBe('phone');
252+
expect(component.formTitle).toBe('Verify Phone Number');
253+
});
239254
});

src/app/auth/components/verify/verify.component.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export class VerifyComponent implements OnInit {
3030
verifyingEmail = true;
3131
verifyingPhone = false;
3232

33+
currentVerifyFlow: 'none' | 'email' | 'phone' = 'none';
34+
3335
needsEmail: boolean;
3436
needsPhone: boolean;
3537

@@ -62,10 +64,19 @@ export class VerifyComponent implements OnInit {
6264
}
6365
const queryParams = route.snapshot.queryParams;
6466

65-
this.needsEmail =
66-
(account.emailNeedsVerification() || queryParams.sendEmail) &&
67-
!queryParams.sendSms;
68-
this.needsPhone = account.phoneNeedsVerification() || queryParams.sendSms;
67+
this.needsEmail = account.emailNeedsVerification();
68+
this.needsPhone = account.phoneNeedsVerification();
69+
70+
if ((this.needsEmail || queryParams.sendEmail) && !queryParams.sendSms) {
71+
this.currentVerifyFlow = 'email';
72+
} else if (
73+
(this.needsPhone || queryParams.sendSms) &&
74+
!queryParams.sendEmail
75+
) {
76+
this.currentVerifyFlow = 'phone';
77+
} else {
78+
this.currentVerifyFlow = 'none';
79+
}
6980

7081
this.verifyForm = fb.group({
7182
token: [queryParams.token || ''],
@@ -99,12 +110,15 @@ export class VerifyComponent implements OnInit {
99110
}
100111
}
101112

102-
if (!this.needsEmail && this.needsPhone) {
103-
this.verifyingEmail = false;
104-
this.verifyingPhone = true;
105-
this.formTitle = 'Verify Phone Number';
106-
} else if (!this.needsEmail) {
107-
this.router.navigate(['/private'], { queryParamsHandling: 'preserve' });
113+
switch (this.currentVerifyFlow) {
114+
case 'phone':
115+
this.verifyingEmail = false;
116+
this.verifyingPhone = true;
117+
this.formTitle = 'Verify Phone Number';
118+
break;
119+
case 'none':
120+
this.router.navigate(['/private'], { queryParamsHandling: 'preserve' });
121+
break;
108122
}
109123
}
110124

0 commit comments

Comments
 (0)