3

enter image description here

this undefined error is thrown by Azure B2C when i try to signup an existing user can i fix this issue somhow?

momin naveed
  • 141
  • 10
  • 1
    We are having the same error, did you resolve this? it's returning JSON but the UI shows undefined, happens both in a default or custom template: {"status":"400","errorCode":"ViralErrorUserCreationConflict","message":"A user with the specified ID already exists. Please choose a different one."} – fizgig Jan 05 '23 at 20:43
  • 1
    still facing this issue maybe some one from microsoft will fix it soon – momin naveed Jan 09 '23 at 11:38
  • Thanks for the update, I have a few bug reports into them myself. – fizgig Jan 09 '23 at 19:00

2 Answers2

2

Workaround

To workaround this issue and display the correct error message, you can do the following:

  1. If you haven't already, follow these steps to add a custom HTML template for the page.
  2. If you haven't already, follow these steps to enable JavaScript in your custom template.
  3. In the B2C authentication screens, open the browser dev tools and reproduce the error that causes "undefined" to be displayed. Then, locate the last network request and inspect the response JSON, noting the errorCode and message properties. Browser dev tools, showing a network response JSON.
  4. Add the following script to the bottom of your custom HTML template (inside the <body> tag), replacing the error code and message with the one from your devtools. If you like, you can also customise the error message.
<script type="text/javascript">
if (CONTENT) {
  CONTENT['UserAccountNotFound'] = CONTENT['UserAccountNotFound'] ?? 'A user with the specified credential could not be found.'
}
</script>
  1. Upload the updated HTML template, and the correct error message should not be displayed.

Explanation

It seems that undefined is being displayed due to Microsoft having a bug in the page's JavaScript. The variable u is initially set to the correct message, while f is set to the string 'undefined' as the errorCode is not found in the page's lookup dictionary. Then the next line contains u = f which results in the string 'undefined' being printed as the error. JavaScript with Microsoft's bug

To workaround this, we need lookupLanguage to return the correct string. To do this, we need to add items to the page's lookup dictionary, which helpfully is a global variable named CONTENT that can be easily modified in a custom script.

In the future, Microsoft will hopefully fix this bug so that the workaround will no longer be needed.

Daniel Elkington
  • 2,560
  • 6
  • 22
  • 35
2

This issue has been fixed with selfasserted version 2.1.19. See: https://learn.microsoft.com/en-us/answers/questions/1154586/azure-b2c-gives-undefined-as-the-error-message-whe and https://learn.microsoft.com/en-us/azure/active-directory-b2c/page-layout#self-asserted-page-selfasserted

engell
  • 36
  • 3
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 25 '23 at 11:44