Skip to content
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

fix: error propagation totp issue display toast #401

Conversation

Spiral-Memory
Copy link
Collaborator

@Spiral-Memory Spiral-Memory commented Jan 15, 2024

Fixed the authentication flow for situations where 2FA is enabled, addressed the propagation of error messages so that error message will be displayed when password is incorrect, and also resolved the z-index issue related to the displayed error message.

Acceptance Criteria fulfillment

[x] Resolved the issue with the opening of the TOTP modal when 2FA is enabled, prompting users to enter OTP for authentication.

[x] Addressed the proper propagation of required errors from auth to the API and frontend to ensure successful implementation and incorrect credentials error will be displayed.

[x] Additonally, fixed the z-index problem with the toast message, ensuring it now appears above the overlay (Modal Backdrop) instead of below it.

Fixes #400
Fixes #407

Video/Screenshots

2024-01-16.00-41-21.mp4

user,
password,
code,
try {
Copy link
Member

Choose a reason for hiding this comment

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

Hey, we could catch the error in the EmbeddedChat itself. Was there any specific reason to use try/catch here?

Copy link
Collaborator Author

@Spiral-Memory Spiral-Memory Jan 18, 2024

Choose a reason for hiding this comment

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

@abhinavkrin, I added a try-catch block in RocketChatAuth.ts because frontend error handling relies on specific error properties such as 'totp-required', 'Unauthorized', and 'totp-invalid', which are parsed from the server response. In Api.ts, within the packages/auth folder, the ApiError class wraps the server response with a message and endpoint when the status is not OK from the Rocket.Chat server response. Before parsing it into JSON, I check if it's an instance of the ApiError class because then only i can access the response property.

Handling it in EmbeddedChatApi.ts is possible, but it requires exporting the ApiError class from Api.ts in packages/auth and importing it into EmbeddedChatApi.ts in packages/api to check whether this is an instance of ApiError . The approach I took was more straightforward because we already have access to the ApiError class. Additionally, when it is not an instance of ApiError, I rethrow the error, and those cases will be handled as before.

Another reason for this approach is its similarity to the existing pattern in the getCurrentUser function in RocketChatAuth.ts, making the structure consistent rather than exporting and importing a class.

These are the reasons why I did it this way. Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

Hey @Spiral-Memory I understand, but the package auth is built keeping in mind that it could be used by other projects also. So we would want to have a uniform behavior.
There are other ways you can export the error reason.
error
You can pass more information though the cause.
or
Add a code property to error object
or
Make use of the response property of ApiError

In short, the error instance should be thrown from the function instead of a simple JSON object.

@Spiral-Memory
Copy link
Collaborator Author

@abhinavkrin , I have explained the reason why it is done like this. Kindly review this and let me know. It addresses the 2FA OTP entry issue, displays a toast error for login failures, and indicates OTP invalid status—all of which are related to server responses. The frontend part has been in place for a while, but it wasn't working correctly due to server responses. Additionally, this PR resolves the issue of the toast message color; the opacity was on the overlay color, but it was expected to be a white background. Also, the z-index has been fixed.

user,
password,
code,
try {
Copy link
Member

Choose a reason for hiding this comment

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

Hey @Spiral-Memory I understand, but the package auth is built keeping in mind that it could be used by other projects also. So we would want to have a uniform behavior.
There are other ways you can export the error reason.
error
You can pass more information though the cause.
or
Add a code property to error object
or
Make use of the response property of ApiError

In short, the error instance should be thrown from the function instead of a simple JSON object.

@Spiral-Memory
Copy link
Collaborator Author

Spiral-Memory commented Feb 5, 2024

Got it @abhinavkrin I will do that and let you know.

@Spiral-Memory Spiral-Memory force-pushed the fix/error-propagation_totp-issue_display-toast branch from 479ff17 to d1e7763 Compare February 5, 2024 21:46
exported ApiError from auth

fixed background color and z-Index of toastBar
@Spiral-Memory Spiral-Memory force-pushed the fix/error-propagation_totp-issue_display-toast branch from d1e7763 to 6177621 Compare February 5, 2024 21:48
@Spiral-Memory
Copy link
Collaborator Author

Spiral-Memory commented Feb 5, 2024

Hey @abhinavkrin, I am no longer handling it in RocketChatAuth.ts. I have just exported it and imported it in Embeddedchat.ts, handling it there only. Therefore, I am no longer making changes to the Auth files and now utlising ApiError response object directly from Embeddedchat.ts as you suggested. Thank you for your feedback.

I have tested it and everything is working fine as expected.

Copy link
Member

@abhinavkrin abhinavkrin left a comment

Choose a reason for hiding this comment

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

LGTM! Great work!

@abhinavkrin abhinavkrin merged commit 54647a8 into RocketChat:develop Feb 6, 2024
1 check passed
@Spiral-Memory Spiral-Memory changed the title Fix/error propagation totp issue display toast fix: error propagation totp issue display toast Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants