Created
June 4, 2026 16:59
-
-
Save joshcanhelp/eedee93806471f12a02646326fbd9bd9 to your computer and use it in GitHub Desktop.
Auth0 Refresh Token Metadata Polyfill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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