I am trying to retrieve my app_metadata through the useUser nextJS hook but it keeps failing.
I followed this answer to setup a rule to return the metadata but still do not get the info when I call useUser.
SDK: @auth0 /nextjs-auth0
Version: v1.2.0
Hi all,
First time user of Auth0 and Next.js here so excuse any oversight in my question below.
I want to add two custom properties (I think they’re called claims in the auth world) to each user. These properties essentially represent the User profile type and a particular resource they have access to.
I’ve added the two properties under app_metadata from the Auth0 dashboard and am using Passwordless Email login using a code.
Now, in Next.js I want …
I am very stuck and have tried setting up rules/claims to do this but have made no progress.
Hi @ryanwhite ,
Welcome to the Auth0 Community!
How is it failing? Can you try to decode the token with jwt.io and see if the claim you are expecting is there?
Hello and thank you @dan.woda
So maybe I am misunderstanding how I should be retrieving the info but when I call useUser
in nextjs it returns the user info but no metadata.
This is my rule
function(user, context, callback) {
const namespace = 'https://myapp.example.com/';
context.idToken[namespace + 'stripe_id'] = user.app_metadata.stripe_id;
callback(null, user, context);
}
Then this is what useUser returns
email: "EMAIL_HERE"
email_verified: false
name: "EMAIL_HERE"
nickname: "hello"
picture: "GRAVATAR_HERE"
sub: "auth0|AUTH0_ID"
updated_at: "2021-07-21T21:47:30.606Z"
I have set in the auth0 dashboard the app_metadata of
{
“stripe_id”: “test-value”
}
1 Like
Oh man I feel dumb. I logged out of my app and back in and it started working. How would I be able to force the retrieval of this data without forcing users to log in/out again @dan.woda ?
@ryanwhite ,
It must be that the initial token is getting issued before the stripe ID is set in the user’s metadata. How are you setting that value in the user’s app_metadata?
I have switched to setting it in my app with the management API and it seems to be working okay. I will keep testing but I think I have got it figure out. Thanks for the help!
Glad you found a solution!
system
Closed
August 11, 2021, 7:13pm
9
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.