我尝试发送凭据,但出现此错误。
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=*******. (Reason: CORS request did not succeed).
(function () {
var config = {
apiKey: "*******",
authDomain: "*******",
databaseURL: "*******",
projectId: "*******",
storageBucket: "*******",
messagingSenderId: "*******"
};
firebase.initializeApp(config);
const email = document.getElementById('email');
const password = document.getElementById('password');
const btnSignUp = document.getElementById('btnSignUp');
btnSignUp.addEventListener('click', e => {
const mail = email.value;
const pass = password.value;
firebase.auth().createUserWithEmailAndPassword(mail, pass).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode == 'auth/weak-password') {
alert('The password is too weak.');
} else {
alert(errorMessage);
}
console.log(error);
});
});
}());
如何解决 CORS 请求被阻塞的问题?
最佳答案
你的 firebase 导入是错误的,使用这个:
<!-- Firebase App is always required and must be first -->
<script src="https://www.gstatic.com/firebasejs/5.1.0/firebase-app.js"></script>
<!-- Add additional services that you want to use -->
<script src="https://www.gstatic.com/firebasejs/5.1.0/firebase-auth.js"></script>
关于javascript - 使用其身份验证方法在 firebase 上创建用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51181298/