Итак, у меня есть эта функция, которая срабатывает, когда пользователь нажимает кнопку входа в систему с помощью кнопки Google:
Код: Выделить всё
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);
}
};
< blockquote>
не удалось войти в систему с помощью Google. FirebaseError: Firebase: ошибка (auth/popup-closed-by-user)
Тогда он, кажется, что-то делает в всплывающее окно при загрузке и просто закрывается. Я добавил в индекс js:
Код: Выделить всё
app.use(helmet(
{
contentSecurityPolicy: {
directives: {
"default-src": ["'self'"],
"script-src": [
"'self'",
"'unsafe-eval'",
"https://apis.google.com",
"https://www.gstatic.com",
"https://firebase.googleapis.com",
"https://www.googletagmanager.com",
"https://accounts.google.com",
"https://www.google.com",
],
"img-src": [
"'self'",
"https://firebasestorage.googleapis.com",
"https://cdn.pixabay.com",
"https://lh3.googleusercontent.com",
],
"connect-src": [
"'self'",
"https://www.googleapis.com",
"https://identitytoolkit.googleapis.com",
"https://securetoken.googleapis.com",
"https://firebase.googleapis.com",
"https://firebaseinstallations.googleapis.com",
"https://region1.google-analytics.com",
],
"frame-src": [
"'self'",
"my-website-url.onrender.com",
"my-firebase-url.firebaseapp.com",
"https://accounts.google.com",
"https://www.google.com",
],
},
},
}
));
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/793 ... ogin-issue