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

[BUG] 401 error after register a customer using an login different from the email. #1464

Closed
luanrafaelpinheiro opened this issue Oct 5, 2023 · 1 comment
Labels
Acknowledged Team has responded to issue

Comments

@luanrafaelpinheiro
Copy link
Contributor

Summary

When attempting to create a new customer account with a custom login (different from the email address), the customer account is successfully created. However, a 401 error is encountered when the registration process tries to authenticate using the email as the username. The issue arises from the assumption within the registration function that the email will always serve as the customer's username, which may not be the case. It is recommended to use the 'login' field instead of the email from the registration body for authentication.

Steps To Reproduce

  1. Call the register.mutateAsync method with different values for 'login' and 'email':
import { AuthHelpers, useAuthHelper } from '@salesforce/commerce-sdk-react'
const register = useAuthHelper(AuthHelpers.Register)
await register.mutateAsync({
  customer: {
    firstName: data.firstName,
    lastName: data.lastName,
    email: data.email,
    login: data.username
  }
})

Upon analyzing the requests, a 401 error is observed after the registration request because the function attempts to perform authentication using the email, which, in this case, is not the customer's username.

Expected Result

After the registration request, the user should be authenticated using the provided 'login,' which can be either the email or any other valid information.

Actual Result

After registration, a 401 error occurs because the function attempts to use the email as the username for authentication.
image

Workaround

import { AuthHelpers, useAuthHelper } from '@salesforce/commerce-sdk-react'
const register = useAuthHelper(AuthHelpers.Register)
const login = useAuthHelper(AuthHelpers.LoginRegisteredUserB2C)

try {
  await register.mutateAsync({
    customer: {
      firstName: data.firstName,
      lastName: data.lastName,
      email: data.email,
      login: data.username
    }
  })

} catch (error) {
  if (error.response && error.response.status == 401) {
    await login.mutateAsync({username: body.customer.login, password: body.password})
  }
}

Additional Information

It is suggested to replace the usage of the email as the username with the 'login' field in the 'register' function.
image

luanrafael pushed a commit to luanrafael/pwa-kit that referenced this issue Oct 5, 2023
@wjhsf wjhsf added the Acknowledged Team has responded to issue label Oct 6, 2023
luanrafael pushed a commit to luanrafael/pwa-kit that referenced this issue Oct 6, 2023
…ration process

Issue SalesforceCommerceCloud#1464

Signed-off-by: Luan Rafael Pinheiro <luanrafael.pinheiro@salesforce.com>
luanrafael pushed a commit to luanrafael/pwa-kit that referenced this issue Oct 6, 2023
…ration process

Issue SalesforceCommerceCloud#1464

Signed-off-by: Luan Rafael Pinheiro <luanrafael.pinheiro@salesforce.com>
luanrafael pushed a commit to luanrafael/pwa-kit that referenced this issue Oct 6, 2023
…ration process

Issue SalesforceCommerceCloud#1464

Signed-off-by: Luan Rafael Pinheiro <luanrafael.pinheiro@salesforce.com>
wjhsf pushed a commit that referenced this issue Oct 6, 2023
…ration process (#1465)

* Refactor: Use 'login' for authentication instead of 'email' in registration process
Issue #1464

Signed-off-by: Luan Rafael Pinheiro <luanrafael.pinheiro@salesforce.com>

* update changelog

Signed-off-by: Luan Rafael Pinheiro <luanrafael.pinheiro@salesforce.com>

* update changelog

Signed-off-by: Luan Rafael Pinheiro <luanrafael.pinheiro@salesforce.com>

* update changelog

Signed-off-by: Luan Rafael Pinheiro <luanrafael.pinheiro@salesforce.com>

---------

Signed-off-by: Luan Rafael Pinheiro <luanrafael.pinheiro@salesforce.com>
@wjhsf
Copy link
Contributor

wjhsf commented Oct 10, 2023

Closed via #1465. Thanks for the contribution!

@wjhsf wjhsf closed this as completed Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Acknowledged Team has responded to issue
Projects
None yet
Development

No branches or pull requests

2 participants