I’m currently building my first app for client but I’m experiencing an error while testing the sign in functionality i get:
http proxy error: /api/auth/google
background: I’m using a mern architecture with Firebase google oauth, it was previously working but seems to not be currently i got a link to this doc
https://firebase.google.com/docs/auth/web/redirect-best-practices?hl=en&authuser=1&_gl=1*l8w56g*_ga*MTg5NDE0NTUwOC4xNzE5Njk4Mjcw*_ga_CW55HF8NVT*MTcxOTY5ODI3MC4xLjEuMTcxOTcwMDgxMC40MS4wLjA.#signinwithpopup
but dont quite see what in my code needs to change
`
import { GoogleAuthProvider, getAuth, signInWithPopup } from 'firebase/auth'
import { app } from '../firebase';
import { useDispatch } from 'react-redux';
import { signInSuccess } from '../redux/user/userSlice';
import { useNavigate } from 'react-router-dom';
export default function OAuth() {
const dispatch = useDispatch();
const navigate = useNavigate();
const handleGoogleClick = async () => {
try {
const provider = new GoogleAuthProvider();
const auth = getAuth(app);
const result = await signInWithPopup(auth, provider);
const res = await fetch('/api/auth/google', {
method: 'POST',
headers: {
'Content-Type': 'application/json', // Ensure correct content-type header
},
body: JSON.stringify({
name: result.user.displayName,
email: result.user.email,
photo: result.user.photoURL
}),
});
// Log the raw response
const text = await res.text();
console.log('Raw response:', text);
// Parse the response if it is JSON
const data = JSON.parse(text);
console.log('Parsed JSON:', data);
// Assuming the response is valid, dispatch the sign-in success action and navigate
dispatch(signInSuccess(data));
navigate('/');
} catch (error) {
console.log('Could not sign in with Google', error);
}
};
return (
<button onClick={handleGoogleClick}type='button'className='bg-yellow-500 text-white p-3 rounded-lg uppercase hover:opacity-95'>Continue with google</button>
)
}
is anyone having similar issues with their application i tried different browser’s as well same issue
when trying different browsers issues remains the same.
user25487616 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.