我是新手,我正在嘗試使用 firebase 創建登錄螢屏身份驗證,下面是我的代碼
import { StyleSheet, Text, View, KeyboardAvoidingView,TextInput, TouchableOpacity } from 'react-native'
import React, { useState } from 'react'
import {auth} from '../firebase'
const LogScreen = () => {
const[email,setEmail] = useState()
const[password,setPassword] =useState()
const handleSignUp = ()=>{
auth
.createUserWithEmailAndPassword(email, password)
.then(userCredentials=>{
const user = userCredentials.user;
console.log(user.email);
})
.catch(error=>alert(error.message))
}
return (
<KeyboardAvoidingView
style={styles.container}
behavior="padding">
<View style={styles.inputContainer}>
<TextInput
value ={email}
defaultValue={''}
onChangedText={(text)=>setEmail(text)}
style = {styles.input}
placeholder="Email"
/>
<TextInput
value ={password}
defaultValue={''}
onChangedText={(text)=>setPassword(text) }
style = {styles.input}
placeholder="Password"
secureTextEntry
/>
</View>
<View style={styles.buttonContainer}>
<TouchableOpacity
onPress={()=>{}}
style = {styles.loginButton}
>
<Text styles = {styles.buttonText}>Log in</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={handleSignUp}
style = {styles.registerButton}
>
<Text styles = {styles.buttonText}>Register</Text>
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
)
}
export default LogScreen
const styles = StyleSheet.create({
input:{
backgroundColor:'white',
borderColor:'#ADD8E6',
borderWidth:2,
padding:5,
margin:5,
borderRadius:10,
justifyContent:'center',
alignItems:'center'
},
container:{
flex:1,
justifyContent:'center',
alignItems:'center'
},
inputContainer:{
width:'75%'
},
buttonContainer:{
width:'100%',
backgroundColor:'#CCCCFF',
alignItems:'center'
},
loginButton:{
borderRadius:10,
width:'50%',
backgroundColor:'#dca4c3',
height:40,
padding:5,
textAlignVertical:'center',
alignItems:'center',
borderWidth:3,
marginTop:10
},
buttonText:{
color:'white',
fontWeight:'800',
fontSize:8
},
registerButton:{
borderRadius:10,
backgroundColor:'#dca4c3',
width:'50%',
height:40,
padding:5,
textAlignVertical:'center',
alignItems:'center',
borderWidth:3,
marginTop:10
},
})
但是,當嘗試輸入電子郵件和密碼并單擊注冊按鈕(目前只設定注冊按鈕)時,會出現一條錯誤訊息,上面寫著createUserWithEmailAndPassword failed: First argument "email" must be a valid string.此外,當應用程式在 expo 上啟動時,模擬器中會出現一條警告,上面寫著AsyncStorage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-async-storage/async-storage' instead of 'react-native'。誰能向我解釋如何解決錯誤以及警告的含義。
uj5u.com熱心網友回復:
讀取用戶輸入的事件是“onChangeText”而不是“onChangedText”
,您可以閱讀更多相關資訊:
https ://reactnative.dev/docs/textinput
uj5u.com熱心網友回復:
正如警告所說
AsyncStorage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-async-storage/async-storage' instead of 'react-native'
只需npm install @react-native-async-storage/async-storage
在 npmjs.com 上搜索包以獲取示例用法
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/493083.html
標籤:反应式
