Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未调度React redux操作_Javascript_Reactjs_Redux_Next.js_Redux Thunk - Fatal编程技术网

Javascript 未调度React redux操作

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

我正在尝试在我的react next js应用程序中使用google实现身份验证。我将访问令牌发送到后端,后端会检查令牌是否有效,如果有效,它会在头中返回一个令牌以访问受保护的资源。当我集成redux时,redux thunk似乎阻止了请求,请求只发送到google,而不发送到我的后端。我没有收到来自后端的任何响应,甚至在服务器中观察到日志,但没有请求

这段代码运行良好,并返回令牌

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))}
谢谢,它现在正在工作