momin naveed
momin naveed

Reputation: 301

Azure b2c throwing undefined error which is vague error and should be user/email exists error?

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?

Upvotes: 3

Views: 1276

Answers (2)

Daniel Elkington
Daniel Elkington

Reputation: 3647

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.

Upvotes: 2

Related Questions