Cor*_*ton 5 firebase react-native expo
我第一次在我的应用程序中实现 firebase。我收到此错误:
“Firebase:错误(身份验证/无效值-(电子邮件),-在标量字段上启动对象无效值-(密码),-在标量上启动对象-场地)。”
我的代码:
注册屏幕.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))
}
Run Code Online (Sandbox Code Playgroud)
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 }
Run Code Online (Sandbox Code Playgroud)
我在此处找到的文档中找不到此错误
我已确认用于身份验证的电子邮件和密码有效。
预先感谢您提供的任何帮助,如果您需要任何其他信息,请告诉我。
回答我自己的问题:
在我的状态下,我有:
const [email, setEmail] = useState({ value: '', error: '' })
const [password, setPassword] = useState({ value: '', error: '' })
Run Code Online (Sandbox Code Playgroud)
在我的输入字段中,我有:
<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
/>
Run Code Online (Sandbox Code Playgroud)
我仍然不确定错误的确切含义是什么,但我将状态更改为:
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
Run Code Online (Sandbox Code Playgroud)
我的输入字段为:
<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
/>
Run Code Online (Sandbox Code Playgroud)
现在我没有任何问题了。虽然我想在状态管理中设置错误,但我只会解决它并做其他事情。
| 归档时间: |
|
| 查看次数: |
6255 次 |
| 最近记录: |