我有以下连接到firebase的设置,但出于某种原因,在浏览器控制台中,它显示auth.createUserWithEmailAndPassword()不是函数.我的代码有问题吗?这是登录.js
import React, { useState } from 'react';
import './Login.css'
import { Link, useNavigate } from "react-router-dom";
import { auth } from "firebase/auth";
function Login() {
const navigate = useNavigate();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const signIn = e => {
e.preventDefault();
//some fancy firebase
}
const register = e => {
e.preventDefault();
auth
.createUserWithEmailAndPassword(email, password)
.then((auth) => {
// it successfully created a new user with email and password
if (auth) {
navigate.push('/')
}
})
.catch(error => alert(error.message))
}
return (
<div className='login'>
<Link to='/'>
<img
className="login__logo"
src='https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Amazon_logo.svg/1024px-Amazon_logo.svg.png' alt=" "
/>
</Link>
<div className='login__container'>
<h1>Sign-in</h1>
<form>
<h5>E-mail</h5>
<input type='text' value={email} onChange={e => setEmail(e.target.value)} />
<h5>Password</h5>
<input type='password' value={password} onChange={e => setPassword(e.target.value)} />
<button type='submit' onClick={signIn} className='login__signInButton'>Sign In</button>
</form>
<p>
By signing-in you agree to the AMAZON FAKE CLONE Conditions of Use & Sale. Please
see our Privacy Notice, our Cookies Notice and our Interest-Based Ads Notice.
</p>
<button onClick={register} className='login__registerButton'>Create your Amazon Account</button>
</div>
</div>
)
}
export default Login
我也会发布我的firebase.这里是js
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
import { getAuth } from 'firebase/auth';
const firebaseConfig = {
apiKey: "Not mentioning my firbase config in and below",
authDomain: "c",
projected: " ",
storageBucket: " ",
messagingSenderId: " ",
appId: " ",
measurementId: " "
};
// const firebaseApp = firebase.initializeApp(firebaseConfig);
const firebaseApp = initializeApp(firebaseConfig);
// const db = firebaseApp.firestore();
const db = getFirestore(firebaseApp);
//const auth = getAuth(app);
//const auth = firebase.auth();
const auth = getAuth(firebaseApp);
export { db, auth };
我删除了auth.来自auth.createUserWithEmailAndPassword(邮箱,密码).然后(cred=>;{console.log(cred);现在它给出了浏览器控制台中的当前错误:
Uncaught (in promise) TypeError: Cannot create property '_canInitEmulator' on string 'test1234@gmail.com
try 了以前在stack overflow中使用的所有解决方案,但都不起作用.阅读了firebase v.9.0+新模块的一些文档,但仍不了解.对于firebase与react js的授权,我将不胜感激.