[英]React-redux action is not getting dispatched
I am trying to implement authentication with google in my react next js app.我正在尝试在我的 react next js 应用程序中使用 google 实现身份验证。 I am sending the access token to my backend and the backend checks if the token is valid and if it is good it returns a token in the header to access the protected resources.
我将访问令牌发送到我的后端,后端检查令牌是否有效,如果有效,它会在 header 中返回一个令牌以访问受保护的资源。 when I integrate redux, redux-thunk seems to block the request, the request is only sent to google and not to my backend.
当我集成 redux 时,redux-thunk 似乎阻止了请求,请求只发送到谷歌而不是我的后端。 I do not receive any response from my backend and I even observed the logs in the server but no request.
我没有收到来自后端的任何响应,我什至观察到服务器中的日志但没有请求。
this code works well and it returns the token此代码运行良好,它返回令牌
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))
};
but with this code below with redux-thunk not working, the request is sent to google as well but not in my backend但是下面这段代码在 redux-thunk 不工作的情况下,请求也被发送到谷歌,但不在我的后端
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))
}
};
The login button登录按钮
<GoogleLogin
clientId={config.GOOGLE_CLIENT_ID}
buttonText="Login"
onSuccess={responseGoogle}
onFailure={onFailure}
isSignedIn
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.