App Metadata (app_metadata) not included in getIdTokenClaims() results

  • This code works in my DEV and QA tenants
  • It is NOT working in my Production tenant
  1. In the User’s profile, we set a custom field “fooId” in the App Metadata (app_metadata) - see screen shot
  2. 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]);

Screenshot 2024-02-10 at 6.17.34 PM

Hey there @craigp welcome to the community!

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);
};

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