Skip to content

Instantly share code, notes, and snippets.

@joshcanhelp
Created June 4, 2026 16:59
Show Gist options
  • Select an option

  • Save joshcanhelp/eedee93806471f12a02646326fbd9bd9 to your computer and use it in GitHub Desktop.

Select an option

Save joshcanhelp/eedee93806471f12a02646326fbd9bd9 to your computer and use it in GitHub Desktop.
Auth0 Refresh Token Metadata Polyfill
const refreshTokenSetMetadata = (key, value) => {
if (useRefreshTokenMetadata) {
api.refreshToken.setMetadata(key, value);
} else {
const rtIdentifier = event.refresh_token?.id ?? event.user.user_id;
logLine(`Setting cache key RT:${rtIdentifier}:${key} to value: ${value}`);
api.cache.set(`RT:${rtIdentifier}:${key}`, value, {
ttl: 365 * 24 * 60 * 60 * 1000, // 1 year in milliseconds
});
}
logLine(`Metadata check for ${key}: ${refreshTokenGetMetadata(key)}`);
};
const refreshTokenGetMetadata = (key) => {
if (useRefreshTokenMetadata) {
return event.refresh_token?.metadata?.[key];
} else {
const rtId = event.refresh_token?.id;
const rtValue = api.cache.get(`RT:${rtId}:${key}`)?.value;
if (rtId && rtValue) {
console.log(`Using RT ID = RT:${rtId}:${key}; value = ${rtValue}`);
return rtValue;
}
const userId = event.user.user_id;
const userValue = api.cache.get(`RT:${userId}:${key}`)?.value;
console.log(
`Using User ID = RT:${userId}:${key}; value = ${userValue} (fallback since no RT ID)`
);
return userValue;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment