Auth0 Home Blog Docs

The lock.getProfile method is being called twice



I’m using Lock version 10.2.2 with Angular 1.x front-end and .NET back-end. I followed an existing example and I noticed that lock.getProfile is being call twice.

The scenario is the user logs in and it will write the Auth0 user ID to our database. I noticed that two records are stored with the same user_id.

I checked that the lock.getProfile is being called twice. I couldn’t find where this is being call twice.

// This method is called from
function registerAuthenticationListener() {
    lock.on('authenticated', function (authResult) {
        localStorage.setItem('id_token', authResult.idToken);

        lock.getProfile(authResult.idToken, function (error, profile) {
            if (error) {
                return console.log(error);

            localStorage.setItem('profile', JSON.stringify(profile));


This does not directly address the symptom you describe in relation to multiple calls, however, based on the information you provided it seems the underlying main issue is that you want to push the Auth0 user identifier and possibly some other profile information into your own database at the time the user logins.

For that scenario, the recommendation would be for you to trigger this synchronization call from a server-side component, for example, an Auth0 rule. The reasoning here is that any synchronization triggered by client-side logic is susceptible to all the things an end-user can do like unexpectedly interrupting the authentication process or refreshing the web application and that would require more effort to make it robust to all those things.

With this in mind, if you implement the synchronization from a rule you can more easily control how it happens. For example, if it’s the first login you would the respective creation process on your system, if it’s an already existing user you could do just an update process as the user identifier would already exist in your system.