-
Notifications
You must be signed in to change notification settings - Fork 1
Use query params to check which device needs verif #560
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #560 +/- ##
==========================================
- Coverage 44.57% 44.56% -0.01%
==========================================
Files 369 370 +1
Lines 11271 11293 +22
Branches 1846 1852 +6
==========================================
+ Hits 5024 5033 +9
- Misses 6083 6092 +9
- Partials 164 168 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight suggested refactor to make sure the code is easy to understand later; also it looks like tests currently fail.
const queryParams = route.snapshot.queryParams; | ||
|
||
this.needsEmail = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable name no longer actually describes what it claims to contain -- specifically, needsEmail
might contain false even though the current user does, in fact, need email. We should be careful here, as this represents tech debt / makes the variable un-intuitive.
Instead of changing the purpose of those variables I think it would be cleaner and more direct to populate and use a new variable which captures our true intent. For instance:
this.currentVerifyFlow = 'none';
if (this.needsEmail && !this.queryParams?.sendSms) {
this.currentVerifyFlow = 'email';
} else if (this.needsPhone && !this.queryParams?.sendEmail) {
this.currentVerifyFlow = 'phone';
}
Later in the component we would then branch behavior based on the value of this.currentVerifyFlow
.
NOTE: I wrote this.queryParams?...
because later we have an if (queryParams)
which indicates it's possible for queryParams to be a nullish value, and accessing it directly would risk an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for still more changes here.
Right now this component has just too many potentially conflicting state-representing-attributes.
We should just have one: currentVerifyFlow
The value of that single attribute should determine what language is rendered, what flows are followed, etc.
Also I looked at the rest of the component and it looks like there is a bit of redundant logic which hasn't been updated. (for instance: onSubmit
has return verifyPromise
which has a bunch of logic around form titles and other things.). I couldn't add a comment insline since it's not part of the diff, but we should got through the entire component and clean it up / remove redundant logic and shift to currentVerifyFlow
this.verifyingPhone = true; | ||
this.formTitle = 'Verify Phone Number'; | ||
break; | ||
case 'none': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels strange to have this switch case in a way that does not cover all three flow cases.
We can do this is because the "default" state of the component is email verification flow, but that is actually a brittle approach -- we could easily modify the defaults not realizing that the default isn't a generic pre-initialization state but is actually an email-initialization state.
I think this is the appropriate time to fix this.
Suggestions:
-
Remove the
this.verifyingEmail
andthis.verifyingPhone
attributes completely -- there is no valid use case where both can be true. Instead we would have ONLYcurrentVerifyFlow
and the renderer would be updated to look at that variable instead. -
Remove
formTitle
-- instead,src/app/auth/components/verify/verify.component.html
should render the appropriate title based on the current verify flow (this is already done for other aspects of the form). -
I think this means you can remove this switch statement entirely. Instead you would have a "sanity" check of "if none then redirect because that shouldn't be the case"
@slifty thanks Dan! This is such a great suggestion! Sorry I didn't catch it earlier |
fe98feb
to
20f21b4
Compare
- Removed verifyingEmail, verifyingPhone, and formTitle properties - Refactored component logic and template to use currentVerifyFlow exclusively - Updated unit tests to align with new flow-based state model - Improved maintainability and reduced risk of inconsistent state
20f21b4
to
700f82b
Compare
Steps to test:
Add phone number
Click verify phone
it should redirect you as expected to phone verification
Navigate back
Go to email verification
It should take you to email verification