craigp
February 11, 2024, 2:22am
1
This code works in my DEV and QA tenants
It is NOT working in my Production tenant
In the User’s profile, we set a custom field “fooId” in the App Metadata (app_metadata) - see screen shot
When I invoke the getIdTokenClaims()
, I only get the out of the box data, not my custom fooId
value
import { useAuth0 } from "@auth0/auth0-react";
import axios from 'axios';
import Select from "react-select";
function OrgNew() {
const { user, getIdTokenClaims } = useAuth0();
const [fooId, setFooId] = useState();
console.log(`OrgNew: init... :: user.fooId: <${user.fooId}>`);
async function getAuthZeroClaims() {
const claims = await getIdTokenClaims();
console.log(`OrgNew: getAuthZeroClaims() :: claims: <${JSON.stringify(claims)}>`);
}
getAuthZeroClaims();
useEffect(() => {
if(user) {
setFooId(user.fooId);
}
console.log(`OrgNew: useEffect() :: user:`, user);
console.log(`OrgNew: useEffect() :: user.fooId: <${user.fooId}>`);
},[user]);
tyf
February 12, 2024, 9:44pm
3
Hey there @craigp welcome to the community!
craigp:
This code works in my DEV and QA tenants
It is NOT working in my Production tenant
Is there any chance you have an Action (or rule) configured to add the app_metadata
as a custom claim in your DEV/QA tenants but not prod? The metadata won’t be included in token claims by default. An action to add this claim might look something like:
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://example.com';
api.idToken.setCustomClaim(`${namespace}/app_metadata`, event.user.app_metadata);
};
system
Closed
February 26, 2024, 11:32pm
4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.