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: Surface all auth server errors during login in email input. #5319

Merged
merged 1 commit into from
Mar 21, 2024

Conversation

SokratisVidros
Copy link
Contributor

@SokratisVidros SokratisVidros commented Mar 19, 2024

What change does this PR introduce?

This PR patches the following issue:

  1. Sign up with Github with user A
  2. Sign out
  3. Try to sign in with the email of user A
  4. The API returns a 400 error not displayed in the Login form right away in smaller screens.

Why was this change needed?

After this PR, all server auth errors will be displayed in the UI.

It also contains some minor copywriting fixes and clean-ups.

Other information (Screenshots)

Before

Screen.Recording.2024-03-20.at.09.57.30.mov

After

Screenshot 2024-03-20 at 00 39 54

Copy link

netlify bot commented Mar 19, 2024

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit 5741bf4
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/65fadd485ddf460008544865
😎 Deploy Preview https://deploy-preview-5319--dev-web-novu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

const { body } = await session.testAgent.post('/v1/auth/login').send({
email: userCredentials.email,
password: userCredentials.password,
context('with OAuth', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the above ☝️ are just indentation changes after adding a context.

Copy link
Contributor

Choose a reason for hiding this comment

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

A new one for me! What is the difference between context and describe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

context is a synonym for describe that is usually available in BDD style APIs. For example https://www.coreycleary.me/better-test-structuring-using-mochas-context

return Array.isArray(error?.message) ? error?.message[0] : error?.message;
}, [error]);
const emailClientError = errors.email?.message;
let emailServerError = parseServerErrorMessage(error);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar changes can be applied to the register flow.

@@ -41,7 +41,8 @@ export class Login {
throw new UnauthorizedException(`Account blocked, Please try again after ${blockedMinutesLeft} minutes`);
}

if (!user.password) throw new ApiException('OAuth user login attempt');
// TODO: Trigger a password reset flow automatically for existing OAuth users instead of throwing an error
if (!user.password) throw new ApiException('Please sign in using Github.');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that returning different errors per auth flow results in User enumeration issues. User enumeration is mostly a privacy concern and should be tackled in a separate PR.

Copy link
Contributor Author

@SokratisVidros SokratisVidros Mar 19, 2024

Choose a reason for hiding this comment

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

Moreover, the error message mentions Github specifically. Currently, it's the only supported OAuth method. When more OAuth providers are added, the copywriting should be tweaked.

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw we have the Google OAuth logic but currently, it's enterprise-only and "disabled".

@SokratisVidros SokratisVidros changed the title fix: Surface all auth errors during login fix: Surface all auth server errors during login in email input. Mar 20, 2024
@SokratisVidros SokratisVidros force-pushed the surface_all_auth_error branch from a11c827 to 6db74f3 Compare March 20, 2024 08:34
This PR patches the following issue:

1. Sign up with Github with user A
2. Sign out
3. Try to sign in with the email of user A
4. The API returns a 400 error not displayed in the Login form.

After this PR, all server auth errors will be displayed in the UI.

It also contains some minor copywriting fixes and clean-ups.
@SokratisVidros SokratisVidros force-pushed the surface_all_auth_error branch from 6db74f3 to 5741bf4 Compare March 20, 2024 12:57
@SokratisVidros SokratisVidros marked this pull request as ready for review March 20, 2024 12:58
Copy link
Contributor

@LetItRock LetItRock left a comment

Choose a reason for hiding this comment

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

🙌

@SokratisVidros SokratisVidros merged commit 6cad582 into next Mar 21, 2024
27 checks passed
@SokratisVidros SokratisVidros deleted the surface_all_auth_error branch March 21, 2024 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants