How do you get user info when using the class based react native API?

Hello!

I’m using the class version of the React Native Auth0 package which is documented sparingly, so I’ve been struggling a bit.

I’ve set up and an Auth0 class instance with:

const auth0 = new Auth0({
        audience: config.audience,
        clientId: config.clientId,
        domain: config.domain,
    })

and am able to authorize with:

auth0.webAuth.authorize().then(credentials => {
            console.log("AUTHORIZED WITH: ", credentials)
})

That gives me what looks like a valid token – though trying to use it via CURL does not succeed, so it is possible I’m missing something already.

But what prompted me to post is this: Given the Auth0 class as created, how do you get out the logged in user’s information (givenName, familyName, email, etc)? I found this page of documentation: Auth | react-native-auth0
Which implied to me that this should work:
const userInfo = await auth0.userInfo()
as it’s a method returning a promise, however I actually see TypeError: auth0.userInfo is not a function (it is undefined).

How does one get this information out in this paradigm?

In case it’s relevant, the reason I’m doing this is because MobX and Hooks do not play well together.

Thanks!

Hi @hearhere,

Welcome to the Auth0 Community!

When you received your access token, have you had the chance to decode it? Say with a JWT library or on jwt.io?

You will need to include the class and method in your code.

For example:
const userInfo = await auth0.auth.userInfo({ token: string })

Could you give that a try and let me know how it goes for you?

Thanks,
Rueben

In the days between your post and my reply I ended up refactoring my code to no longer use the class based method. I created a custom hook that generates my headers using the getCredentials hook from useAuth0() and import that hook everywhere I need to make network requests and pass my headers along to my data store.

I’m not going to re-refactor my code to confirm whether this does or does not work, but I hope it does help someone else.

1 Like

Hi @hearhere,

Thanks for sharing your workaround!

I’m sure it will be useful to someone else in the Community. :clap:

Let us know if you have any other questions.

Cheers,
Rueben

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