Asked By: Anonymous
I am trying to implement authentication with google in my react next js app. 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. when I integrate redux, redux-thunk seems to block the request, the request is only sent to google and not to my backend. 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
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
/>
Solution
Answered By: Anonymous
it is now working, thanks to hmr for giving me the answer.
i just had to trigger the response manually by doing
<GoogleLogin
clientId={config.GOOGLE_CLIENT_ID}
buttonText="Login"
onSuccess={response => dispatch(responseGoogle)}
onFailure={onFailure}
isSignedIn
/>