未及时解析承载令牌:
Bearer [object Promise]
import axios from 'axios'
import { Auth0Client } from "@auth0/auth0-spa-js";
import { auth0Config } from 'src/config';
import { paths } from 'src/paths';
const baseURL = 'http://localhost:3001'
const auth0 = new Auth0Client({
domain: auth0Config.issuer_base_url!,
clientId: auth0Config.client_id!,
cacheLocation: 'localstorage',
authorizationParams: {
audience: auth0Config.audience,
redirect_uri: auth0Config.base_url + paths.auth.auth0.callback,
},
});
async function getToken() {
return await auth0.getTokenSilently()
}
const token = getToken()
export const instance = axios.create({
baseURL,
headers: {
Authorization: `Bearer ${token}`,
}
});
我试过将示例封装在一个函数中,但这也不起作用,因为示例没有可用的方法,如.get,.push等。
1条答案
按热度按时间ippsafx71#
我认为问题在于你的getToken是一个await函数,应该用await来调用,所以consttoken = getToken()
应