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

@W-17458039 - Handle error states for social/passwordless login and reset password #2185

Open
wants to merge 21 commits into
base: feature-passwordless-social-login
Choose a base branch
from

Conversation

yunakim714
Copy link
Collaborator

@yunakim714 yunakim714 commented Jan 6, 2025

Description

Before releasing social and passwordless login, we need to ensure that all error states are covered and presented in the UI.
The following spreadsheet details different error scenarios for social and passwordless login, and what error message is prompted after the error: Social/Passwordless Login Error States

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • Add error handling for the different possible scenarios detailed in the above spreadsheet

How to Test-Drive This PR

Changes are deployed to: https://wasatch-mrt-social-login-poc.mrt-storefront-staging.com/

  • Manually step through each scenario in the spreadsheet and verify that you can see the correct error message

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@yunakim714 yunakim714 marked this pull request as ready for review January 7, 2025 15:54
@yunakim714 yunakim714 requested a review from a team as a code owner January 7, 2025 15:54
@yunakim714 yunakim714 requested a review from hajinsuha1 January 7, 2025 15:54
@hajinsuha1
Copy link
Collaborator

@yunakim714 It seems like users aren't able to resubmit for passwordless login after they cause an error.

Steps to reproduce:

  1. Open the auth modal/login page
  2. Enter a non existent user's email like a@a
  3. Click Continue Securely
  4. Enter an existent user's email like [email protected]

Expected:

  • /passwordless/login API call is made and check email page is displayed

Actual:

  • /passwordless/login API call is not made and login page is still displayed

@yunakim714
Copy link
Collaborator Author

@hajinsuha1 Resolved the bug! Let me know if you still see the issue. Thanks for pointing that out!

Comment on lines 101 to 104
if (res.status !== 200) {
const errorData = await res.json()
throw new Error(`${res.status} ${errorData.message}`)
}
Copy link
Collaborator

@hajinsuha1 hajinsuha1 Jan 9, 2025

Choose a reason for hiding this comment

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

Would we consider moving the logic to throw the error message into commerce-sdk-react?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could... Is there a specific reason to move this to the sdk?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess it would be to simplify the code within the retail react app, if we give the responsibility of throwing the error to the sdk the retail react app doesn't have to worry about checking the status code and can just catch the error when it occurs.

it'll also reduce code duplication, for example for passwordless checkout we wouldn't need to duplicate this logic

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 on moving it to the sdk

@yunakim714 yunakim714 requested a review from alexvuong January 9, 2025 17:18
/callback_uri doesn't match/i,
/error getting user info/i,
/passwordless permissions error/i,
/client secret is not provided/i,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where do we based these messages on? I assume this is from API. What happens if the API adds/removes these messages?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes these messages are from the API. If the error message does not match any of these, the error will show the generic API_ERROR_MESSAGE, which is "Something went wrong! Please try again."

Copy link
Collaborator

Choose a reason for hiding this comment

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

my main concern is to have to maintain this list of constant. In a case where they change a bit of wording and an error will become obsolete.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the spreadsheet of error states I wonder if instead of matching by error message regex we should base it on status code? It seems like it would be possible

@@ -76,7 +77,9 @@ const SocialLogin = ({form, idps}) => {
redirectURI: redirectURI
})
} catch (error) {
const message = formatMessage(API_ERROR_MESSAGE)
const message = /redirect_uri doesn't match/.test(error.message)
? formatMessage(FEATURE_UNAVAILABLE_ERROR_MESSAGE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

To think about this message a little bit, if I recall correctly, if we the social config is not set up correctly, the button to login using socialLogin would not show. This implies the feature should be available. Should we use a better error message? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

why don't we use a generic error instead for simplicity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When discussing with Nathan we decided that if the user has not configured this feature correctly, then we should show this "feature not available" error. Even if the config is not set up correctly, if the user has enabled social login in the config, the button using social login will show.

@alexvuong
Copy link
Collaborator

@yunakim714 Would it possible to provide some steps on how to reproduce these error from the sheet?

@yunakim714
Copy link
Collaborator Author

@alexvuong @hajinsuha1 I added a Steps to Reproduce column in the spreadsheet so you guys can better test this feature!

type: 'manual',
message: formatMessage(API_ERROR_MESSAGE)
})
const message = /error getting user info/i.test(error.message)
Copy link
Collaborator

@hajinsuha1 hajinsuha1 Jan 13, 2025

Choose a reason for hiding this comment

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

@yunakim714 should we also have this error display the CREATE_ACCOUNT_FIRST_ERROR_MESSAGE?

{
  "status_code" : "404 NOT_FOUND",
  "message" : "User not found"
}

Steps to reproduce:

  • enter an email of a user that doesn't exist like a@s
  • Click Continue Securely

Copy link
Collaborator

@hajinsuha1 hajinsuha1 Jan 13, 2025

Choose a reason for hiding this comment

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

Sorry now that I'm trying on your env https://wasatch-mrt-social-login-poc.mrt-storefront-staging.com/ (bvgn_stg) I see it does display the correct error msg while my env that uses zzrf-001 (https://wasatch-mrt-jinsu.mrt-storefront-staging.com/) doesn't.

It looks like bvgn_stg throws a 502 while zzrf_001 throws a 404. I wonder if this is an expected API change?

@@ -46,7 +46,8 @@ const ResetPasswordLanding = () => {
await resetPassword({email, token, newPassword: values.password})
navigate('/login')
} catch (error) {
const message = /Unauthorized/i.test(error.message)
const errorData = await error.response?.json()
const message = /invalid token/i.test(errorData.message)
Copy link
Collaborator

@alexvuong alexvuong Jan 13, 2025

Choose a reason for hiding this comment

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

Nit/non-blocking: Should we move this to constant? 🤔

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