admin管理员组文章数量:1123214
I cannot login with google to my website on production. On development it works fine.
So I have this function that fires when a user clicks login with google button:
import { getAuth, GoogleAuthProvider, 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",
},
body: JSON.stringify({
name: result.user.displayName,
email: result.user.email,
photo: result.user.photoURL,
}),
});
const data = await res.json();
dispatch(signInSuccess(data));
navigate("/");
} catch (error) {
console.log("could not sign in with google", error);
}
};
Thus it works on my dev environment and I am able to login with google account and on production I get the following error when I click on account:
could not sign in with google FirebaseError: Firebase: Error (auth/popup-closed-by-user)
Then it seems to be doing something in the pop-up as it is loading and it just closes itself. I have added to index js:
app.use(helmet(
{
contentSecurityPolicy: {
directives: {
"default-src": ["'self'"],
"script-src": [
"'self'",
"'unsafe-eval'",
";,
";,
";,
";,
";,
";,
],
"img-src": [
"'self'",
";,
";,
";,
],
"connect-src": [
"'self'",
";,
";,
";,
";,
";,
";,
],
"frame-src": [
"'self'",
"my-website-url.onrender",
"my-firebase-url.firebaseapp",
";,
";,
],
},
},
}
));
and to HTML I have added
<meta http-equiv="Content-Security-Policy"
content="script-src 'self' 'unsafe-eval' ; img-src 'self' ; connect-src 'self' ; frame-src 'self' my-website-url.onrender my-firebase-url.firebaseapp ; " />
Would appreaciate a lot if someone can help as I spent a lot of time on this and still stuck, kind of lost hope. The urls are added to authorized domains on firebase. As well added unsafe-eval as it raised some erorrs on console, later will try to solve it with solution that doesn't use it.
本文标签: javascriptFirebase GoogleAuthProvider login issueStack Overflow
版权声明:本文标题:javascript - Firebase GoogleAuthProvider login issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736557478a1944598.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论