【发布时间】:2021-12-07 03:12:12
【问题描述】:
我正在使用 Auth0 通过 JWT 保护我的 API 端点。 “useAuth0().getTokenSilently()”是一个上下文钩子,它抛出“错误:无效的钩子调用”,因为我在 js 文件而不是 React 组件中调用它;我不确定如何解决这个问题。任何建议将不胜感激。 :)
// Actions.js
export const fetchIssues = () => async (dispatch) => {
try {
const token = await useAuth0().getTokenSilently(); // this line is throwing the error.
const response = await api.get("issues", {
headers: {
Authorization: `Bearer ${token}`,
},
});
const responseData = await response.json();
dispatch({ type: FETCH_ISSUES, payload: responseData });
} catch (error) {
console.log(error);
}
};
【问题讨论】:
标签: reactjs authentication redux auth0