Skip to content

Per 9985 entering 2fa incorrect code works#527

Merged
crisnicandrei merged 5 commits intomainfrom
PER-9985-entering-2fa-incorrect-code-works
Feb 11, 2025
Merged

Per 9985 entering 2fa incorrect code works#527
crisnicandrei merged 5 commits intomainfrom
PER-9985-entering-2fa-incorrect-code-works

Conversation

@crisnicandrei
Copy link
Contributor

This pull request fixes the bug that occurs when entering an incorrect code when removing a multi factor method

Steps to test:

  1. Choose any method you want to remove
  2. Send a code
  3. Enter any code but NOT the one that you received
  4. The method should not be removed
    @meisekimiu Do you think this implementation will do? Or should we change the backend as I mentioned on Slack?

@crisnicandrei crisnicandrei force-pushed the PER-9985-entering-2fa-incorrect-code-works branch from 67ab92d to 622de5e Compare February 4, 2025 14:00
@codecov
Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.75%. Comparing base (2342353) to head (8dece3d).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #527      +/-   ##
==========================================
+ Coverage   43.70%   43.75%   +0.04%     
==========================================
  Files         366      366              
  Lines       11211    11215       +4     
  Branches     1840     1841       +1     
==========================================
+ Hits         4900     4907       +7     
+ Misses       6148     6144       -4     
- Partials      163      164       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

data: any = {},
responseClass?: ResponseClass<T>,
options: RequestOptions = defaultOptions,
responseType?: 'json' | 'text',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding this new feature to the HttpV2Service. I think ideally I'd like to see responseType in the options object instead of a positional argument. It makes our public methods have up to five arguments and some internal methods have even more. This can be annoying when we want to make a basic request with default options but we need to adjust the response type because we have to fill out every argument that would have been optional. (I regret having options come after resposneClass since those options are typically set more than the responseClass is).

data: any = {},
method: HttpMethod,
options: RequestOptions,
responseType: any = 'json',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like this typing to be narrowed down instead of being any type.

data: any = {},
responseClass?: ResponseClass<T>,
options: RequestOptions = defaultOptions,
responseType?: 'json' | 'text',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using this 'json' | 'text' typing everywhere, we should probably just define it as a specific type like

type ResponseType = 'json' | 'text';

That way if we ever have to communicate with an external API that uses XML for instance we only have to change this typing on one line instead of many.

return observable.pipe(
map((response: Object | Array<Object>) => {
if (responseType === 'text') {
return [response as unknown as T];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a legitimate question we should probably think about... if the resposneType is text, we should always be returning a string instead of an object so response should just be able to be cast to string here. Of course, this function is expecting an observable of type T[]. I wonder if there's anyway to force T to be string when responseType is set to text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Maybe this could be a separate ticket? I have tried doing just that but I got many errors in different files unrelated to the ticket

method: HttpMethod = 'post',
responseClass?: new (data: any) => T,
options: RequestOptions = defaultOptions,
responseType: 'json' | 'text' = 'json', // NEW: response type parameter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need that comment.

@crisnicandrei
Copy link
Contributor Author

@meisekimiu addressed your comments! Thank you!

@crisnicandrei crisnicandrei requested a review from k8lyn6 February 10, 2025 14:54
Copy link
Collaborator

@k8lyn6 k8lyn6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix does resolve the issue (submitting an incorrect code just takes you back to the beginning). However, I don't think this is the best user experience, as it might still be a little confusing. It would be a better user experience if entering an incorrect code gives you an error and allows you to try entering the code again.

@meisekimiu would this be doable with this ticket, or does it require backend work? If it requires work outside of the ticket, I'll go ahead and approve this and we can create additional tickets.

@meisekimiu
Copy link
Contributor

I believe there would be some additional backend work required to do this properly.

@k8lyn6 k8lyn6 self-requested a review February 10, 2025 21:09
Copy link
Collaborator

@k8lyn6 k8lyn6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @meisekimiu . I'll create an additional ticket and go ahead and mark this as approved. Thanks @crisnicandrei !

Add api call after removing a method
Move the response type to the request options in the http-v2 service
@crisnicandrei crisnicandrei force-pushed the PER-9985-entering-2fa-incorrect-code-works branch from c3bdaaa to 8dece3d Compare February 11, 2025 13:54
@crisnicandrei crisnicandrei merged commit efd4f2a into main Feb 11, 2025
4 checks passed
@crisnicandrei crisnicandrei deleted the PER-9985-entering-2fa-incorrect-code-works branch February 11, 2025 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants