Firebase:错误(auth/invalid-value-(email)),在标量字段上启动对象



这是我第一次在应用程序中实现firebase。我收到这个错误:

Firebase: Error (auth/invalid-value-(email),-starting-an-object-on-a-scalar-field-invalid-value-(password),-starting-an-object-on-a-scalar-field).&;

我代码:

registerscreen.js

import { auth } from '../firebase'
import { createUserWithEmailAndPassword } from "firebase/auth";
export default function RegisterScreen({ navigation }) {
const [name, setName] = useState({ value: '', error: '' })
const [email, setEmail] = useState({ value: '', error: '' })
const [password, setPassword] = useState({ value: '', error: '' })

const handleSignUp =() => {
const nameError = nameValidator(name.value)
const emailError = emailValidator(email.value)
const passwordError = passwordValidator(password.value)
if (emailError || passwordError || nameError) {
setName({ ...name, error: nameError })
setEmail({ ...email, error: emailError })
setPassword({ ...password, error: passwordError })
return
}
auth
createUserWithEmailAndPassword(auth, email, password)
.then(userCredentials => {
const user = userCredentials.user;
console.log(user.email)
})
.catch(error => alert(error.message))
}

firebase.js

// Import the functions you need from the SDKs you need
import * as firebase from "firebase/app";
import { getAnalytics } from "firebase/analytics";
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";

// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyA1zo9ci0RXQYBNUooGtSK2b29OPxOC0GE",
authDomain: "aslassistfinal.firebaseapp.com",
databaseURL: "https://aslassistfinal-default-rtdb.firebaseio.com",
projectId: "aslassistfinal",
storageBucket: "aslassistfinal.appspot.com",
messagingSenderId: "380652280816",
appId: "1:380652280816:web:5f49bf6df4977cdb401b35",
//measurementId: "G-TYX10C1CBE"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
export { auth }

我在这里找到的文档中找不到这个错误

我已经确认我用来认证的邮箱和密码是有效的。

提前感谢您的帮助,如果您需要任何其他信息,请告诉我。

你得到这个错误是因为'email'被初始化为对象这里包含value,误差const [email, setEmail] = useState({value: ", error: ")})

Firebase auth在createUserWithEmailAndPassword(auth, email, password)方法中期望字符串值,所以您需要使用email.value而不是email,密码也是一样。

另一个提示-你可能还想从这里删除你的firebase凭据(firebase.js),因为它们可能会被滥用

回答我自己的问题:

在我的状态下,我有:

const [email, setEmail] = useState({ value: '', error: '' })
const [password, setPassword] = useState({ value: '', error: '' })

在我的输入字段中,我有:

<TextInput
label="Email"
returnKeyType="next"
value={email.value}
onChangeText={(text) => setEmail({ value: text, error: '' })}
error={!!email.error}
errorText={email.error}
autoCapitalize="none"
autoCompleteType="email"
textContentType="emailAddress"
keyboardType="email-address"
/>
<TextInput
label="Password"
returnKeyType="done"
value={password.value}
onChangeText={(text) => setPassword({ value: text, error: '' })}
error={!!password.error}
errorText={password.error}
secureTextEntry
/>

我仍然不确定错误的确切含义是什么,但我把我的状态改为:

const [email, setEmail] = useState('')
const [password, setPassword] = useState('')

和我的输入字段:

<TextInput
label="Email"
returnKeyType="next"
value={email.value}
onChangeText={text => setEmail(text)}
error={!!email.error}
errorText={email.error}
autoCapitalize="none"
autoCompleteType="email"
textContentType="emailAddress"
keyboardType="email-address"
/>
<TextInput
label="Password"
returnKeyType="done"
value={password.value}
onChangeText={text => setPassword(text)}
error={!!password.error}
errorText={password.error}
secureTextEntry
/>

现在我没有任何问题。虽然我想在我的状态管理中设置错误,但我将绕过它并做其他事情。

最新更新