(auth0-react) What is the proper way to get the access token if a user is authenticated?

It looks like you are not returning anything in the getAccessToken function, so it is expected to return undefined. Please try:

const getAccessToken = async () => {
        let token;
        try {
            token = await getAccessTokenSilently();
        } catch (e) {
            if (e.error === 'login_required') {
                // if silent auth fails, fall back to popup
                token = await getAccessTokenWithPopup();
            } else {
                console.error(e);
            }
        }
       return token;
    };
1 Like