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

getUserInfo returns data with a different naming convention than direct Auth0 api calls #798

Closed
Markus-ipse opened this issue Jan 12, 2017 · 4 comments

Comments

@Markus-ipse
Copy link

Lock version: 10.9.1

When calling lock.getUserInfo() the returned objects' keys are camelCased, e.g. userMetadata,
but when I try to update the userMetadata by using the Auth0 API it expects the patch objects' keys to be snake_cased, e.g. user_metadata and also the response from the call is snake_cased.

Sample code:

@Injectable()
export class AuthService {
  // Configure Auth0
  lock = new Auth0Lock(authConfig.clientID, authConfig.domain, {...});

  profile: any;

  constructor(private authHttp: AuthHttp) {

    this.profile = JSON.parse(window.localStorage.getItem('profile'));

    // Add callback for lock `authenticated` event
    this.lock.on('authenticated', (authResult) => {

      this.lock.getUserInfo(authResult.accessToken, (error, profile) => {

        console.log('lock.getUserInfo:', Object.keys(profile));
        // ["emailVerified", "email", "clientID", "userMetadata", "updatedAt", "name", "picture", "userId", "nickname", "identities", "createdAt", "sub"]

        window.localStorage.setItem('profile', JSON.stringify(profile));
        this.user = profile;

      });
    });
  }

  private updateUser(data) {

    this.authHttp.patch(
      withBaseUrl(`/users/${this.profile.userId}`),
      JSON.stringify(data),
      { headers: headers }
    )
      .map(response => response.json())
      .subscribe(
        response => {
          // Update profile
          console.log('authHttp /users/:user_id', Object.keys(response));
          // ["email_verified", "email", "user_metadata", "updated_at", "name", "picture", "user_id", "nickname", "identities", "created_at", "last_ip", "last_login", "logins_count"]
          this.profile = response;
          localStorage.setItem('profile', JSON.stringify(response));
        },
        error => console.error(error.json().message) // Todo: Add error real handling/logging
      );
  }
}

Is this intended behavior?
Do I have to forgo lock.getUserInfo and do a "manual" API-request to get user info instead or is there way I can update user which utilize the same naming convention as lock.getUserInfo?

@glena
Copy link
Contributor

glena commented Jan 12, 2017

Good catch, auth0.js (the js sdk used underneath by Lock) is normalizing all the responses to be camel case but it should not do it with the response from userInfo.

I will fix this on auth0.js and the next release (10.10.0 next week) it will be fixed.

Thank you for reporting.

@rashfael
Copy link

Additionally, the toCamelCase helper seems to be transforming arrays into objects.
{app_metadata: {groups: ["a","b","c"]}}
becomes
{appMetadata: {groups: {0:"a", 1:"b", 2:"c"}}}

@glena
Copy link
Contributor

glena commented Jan 12, 2017

can you check that last one thing with 10.9.2?

I cant repro that one

@glena
Copy link
Contributor

glena commented Jan 12, 2017

nvm, I just did

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants