Javascript 未调度React redux操作
我正在尝试在我的react next js应用程序中使用google实现身份验证。我将访问令牌发送到后端,后端会检查令牌是否有效,如果有效,它会在头中返回一个令牌以访问受保护的资源。当我集成redux时,redux thunk似乎阻止了请求,请求只发送到google,而不发送到我的后端。我没有收到来自后端的任何响应,甚至在服务器中观察到日志,但没有请求 这段代码运行良好,并返回令牌Javascript 未调度React redux操作,javascript,reactjs,redux,next.js,redux-thunk,Javascript,Reactjs,Redux,Next.js,Redux Thunk,我正在尝试在我的react next js应用程序中使用google实现身份验证。我将访问令牌发送到后端,后端会检查令牌是否有效,如果有效,它会在头中返回一个令牌以访问受保护的资源。当我集成redux时,redux thunk似乎阻止了请求,请求只发送到google,而不发送到我的后端。我没有收到来自后端的任何响应,甚至在服务器中观察到日志,但没有请求 这段代码运行良好,并返回令牌 export const responseGoogle = (response) => { cons
export const responseGoogle = (response) => {
const access_token = response.accessToken;
const tokenSend = {access_token}
return axios.post(`http://localhost:8000/api/auth/google/login`, tokenSend)
.then(response => {
console.log(response.data)
})
.catch(error=> console.log(error))
};
但是下面的代码没有使用redux thunk,请求也会发送到google,但不会发送到我的后端
export const responseGoogle = (response) => {
const access_token = response.accessToken;
const tokenSend = {access_token}
return (dispatch) => {
return axios.post(`http://localhost:8000/api/auth/google/login`, tokenSend)
.then(response => {
console.log(response.data)
})
.catch(error=> console.log(error))
}
};
登录按钮
<GoogleLogin
clientId={config.GOOGLE_CLIENT_ID}
buttonText="Login"
onSuccess={responseGoogle}
onFailure={onFailure}
isSignedIn
/>
感谢您给了我答案,它现在正在工作。 我只需要通过执行以下操作手动触发响应
<GoogleLogin
clientId={config.GOOGLE_CLIENT_ID}
buttonText="Login"
onSuccess={response => dispatch(responseGoogle)}
onFailure={onFailure}
isSignedIn
/>
dispatch(响应日志)}
onFailure={onFailure}
伊西涅丁
/>
我不知道什么是GoogleLogin
但是假设你有一个功能组件,你可以尝试const dispatch=usedpatch()
和处理程序:onSuccess={response=>dispatch(responsegogle(response))}
谢谢,它现在正在工作