有人知道 auth0 帮助我! 我们的应用是使用 typescript 上的 vue / vuex 构建的,并处理来自外部api的大量数据。< / p>
我们没有任何单独的登录URL,只是我们的第一页是重定向URL本身,并且第一页是调用外部api来消耗要显示在其上的数据。
以下是重定向处理部分:
//action
async handleRedirectCallback({commit, dispatch}){
//here we use auth0 service, which is also attached below this code block
return auth0.handleRedirectCallback().then(async (token: string) => {
commit("sessionCreate", token)
return auth0.getUser(token).then((res: AxiosResponse) => {
commit("setUser", res.data)
commit("loaded", true)
return Promise.resolve(res);
})
}).catch((auth: boolean) =>{
window.console.log(`${auth}`)
})
}
//In auth0 service
async handleRedirectCallback(){
let token;
let isAuthenticated = false
try {
if (
window.location.search.includes("code=") &&
window.location.search.includes("state=")
) {
const { appState } = await this.auth0Client.handleRedirectCallback();
options.onRedirectCallback(appState);
}
} catch (e) {
return Promise.reject(e) //Here I got rejected!
} finally {
isAuthenticated = await this.isAuthenticated();
if(isAuthenticated){
token = await this.getTokenSilently();
}
}
if(token){
return Promise.resolve(token)
}
return Promise.reject(isAuthenticated)
}
它显示错误:首次加载重定向URL时出现无效状态;如果刷新页面,它可以正常工作,除此问题外,一切都很好。
问题是由于无效状态错误导致外部api调用失败,因为我们需要使用来自auth0的凭据来调用外部api。
任何帮助将不胜感激。 预先感谢!
编辑: 在继续调试时,我发现此承诺被拒绝了:(
auth0Client.handleRedirectCallback();