Validation through third party API in universal login's additonal signup field's validator

I am trying to implement auth0 as IDP for my discourse account. I have added a sign up field at auth0 named username. I want this field to be validated through discourse api, that whatever username, a user enters, it should be looked up in discourse and only validated if it’s available there.
Is there any way I can implement this? The function returns validation before the API call is completed.

Thanks

Hi @yusra.codup,

Welcome to the Community!

Have you considered using the discourse OAuth2 plugin? This is how we have integrated discourse with Auth0, and it should abstract away some of the challenges you are facing.

Hope this helps!

Hello,

Yes I am using discourse oauth2 plugin.
But the issue I am facing is at the universal login side, I want one of my custom field at universal login sign up page to be linked with discourse account. So that when someone signs up through auth0 universal login, he has to enter a username, which will be validated through discourse (checking if this username exists in discourse or not and return validation based on that).

This is the code I have written:

      {
          name: "username_forum",
          placeholder: "Username",
          validator: function(username_forum) {                
            options = [];
            var xhr = new XMLHttpRequest();
            xhr.addEventListener("readystatechange", function() {
              if(this.readyState === 4) {
               response = JSON.parse(this.responseText);  
                username = response;                  
              }
            });
            xhr.open("GET", "https://myapi/discourse/searchbyusername?username="+username_forum);                
            xhr.setRequestHeader("Content-Type", "application/json");
            xhr.send();                
         	
		 return {
                 valid: username.length == 0,
                 hint: "This username is occupied" // optional
              };          
          }
        }

The issue is the validator function completed before the API call is completed and hence wrong validation is being done.

I don’t see a way for this to be implemented with UL. The current flow we use has them enter the extra info into a modul on discourse.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.