I am running into an issue described here: https://community.auth0.com/t/post-login-trigger-only-firing-for-one-application-in-my-tenant-why-not-the-others/182462
Basically, I have a custom action that is triggered post login for my tenant that serves to attach custom metadata to a user’s id token via api.idToken.setCustomClaim()
. In apps using the old v3 SDK, this metadata is returned with the user
object from useUser
without issue. In the beta v4 SDK, this metadata is nowhere to be found.
Is there some action I need to take to ensure my metadata is attached to my idTokens in the V4 SDK or is this a bug?
Hi @relero90,
Welcome back to the Auth0 Community and thank you for your post.
In the V3 version of the NextJS Auth0 SDK any claims added to the ID token were automatically propagated to the user
object. In the V4 version the list of default claims that persist in the user
object does not include the metadata
.
In order to ensure this metadata is passed to the ID token you can use the beforeSessionSaved
hook. Please check out the V4 Migration Guide included in the NextJS SDK for further documentation.
I hope this helped.
Thanks again,
Remus
Adding the following value for beforeSessionSaved
in my options config option for the Auth0 client solved this problem in the v4 SDK for me:
import { Auth0Client, SessionData } from "@auth0/nextjs-auth0/server";
const createAuth0Client = async (brand: string): Promise<Auth0Client> => {
const optionsConfig: Auth0ClientOptions = {
authorizationParameters: {
audience: 'unity',
},
domain:
process.env[`${brand.toUpperCase()}_AUTH0_DOMAIN`] ||
process.env.AUTH0_DOMAIN as string,
clientId:
process.env[`${brand.toUpperCase()}_AUTH0_CLIENT_ID`] ||
process.env.AUTH0_CLIENT_ID as string,
clientSecret:
process.env[`${brand.toUpperCase()}_AUTH0_CLIENT_SECRET`] ||
process.env.AUTH0_CLIENT_SECRET as string,
appBaseUrl:
process.env[`${brand.toUpperCase()}_APP_BASE_URL`] ||
process.env.APP_BASE_URL as string,
secret:
process.env[`${brand.toUpperCase()}_AUTH0_SECRET`] ||
process.env.AUTH0_SECRET as string,
beforeSessionSaved: async (session: SessionData, idToken: string | null): Promise<SessionData> => ({ ...session }),
};
return new Auth0Client(optionsConfig)
}
export default createAuth0Client;
Thanks @relero90 for sharing this with the Community!