@evan.gillogley I just recently implemented something for this and wrote about it Maffin Blog - Next.js feature flags with auth0 (full example of retrieving access token with roles and injecting it to a class to it can be used in the server actions). The snippet:
export default class AccessTokenHolder {
static _accessToken: string;
static get accessToken() {
return Actions._accessToken;
}
static set accessToken(token: string) {
Actions._accessToken = token;
}
}
and how to set it
import { useAuth0 } from '@auth0/auth0-react';
import AccessTokenHolder from './AccessTokenHolder';
export default function useSession(): SessionReturn {
const { getAccessTokenSilently, isAuthenticated } = useAuth0();
const [accessToken, setAccessToken] = React.useState();
React.useEffect(() => {
async function load() {
const token = await getAccessTokenSilently();
AccessTokenHolder.setAccessToken(token);
setAccessToken(token);
}
if (isAuthenticated) {
load();
}
}, [isAuthenticated, getAccessTokenSilently]);
return {
accessToken,
};
Hope it helps!