![](/img/trans.png)
[英]Amplify error: [TypeError: undefined is not an object (evaluating '_awsAmplify.default.configure')] in a React Native, Expo app
[英]undefined is not an object (evaluating 'auth.tenanatId') in firebase react native
我正在使用 firebase 制作一個身份驗證應用程序,我在注冊過程中收到此錯誤,稱為 undefined is not an object (evaluating 'auth.tenantId') 我無法弄清楚我正在使用 react native 你們中的任何一個都可以幫我解決這個錯誤
這是我的錯誤截圖https://i.stack.imgur.com/mupat.png
這是我的代碼
import { Text, View, TextInput, ImageBackground, Button, KeyboardAvoidingView, Platform } from 'react-native';
import AppStyles from '../styles/AppStyles';
import InlineTextButton from '../Components/InlineTextButton';
import React from 'react';
import { auth } from "firebase/app";
import { createUserWithEmailAndPassword, sendEmailVerification } from "firebase/auth";
export default function SignUp({ navigation }) {
const background = require("../assets/background.jpg");
let [email, setEmail] = React.useState("");
let [password, setPassword] = React.useState("");
let [confirmPassword, setConfirmPassword] = React.useState("");
let [validationMessage, setValidationMessage] = React.useState("");
let validateAndSet = (value, valueToCompare, setValue) => {
if (value !== valueToCompare) {
setValidationMessage("Passwords do not match.");
} else {
setValidationMessage("");
}
setValue(value);
};
let signUp = () => {
if (password === confirmPassword) {
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
sendEmailVerification(auth.currentUser);
navigation.navigate("ToDo", { user: userCredential.user });
})
.catch((error) => {
setValidationMessage(error.message);
});
}
}
return (
<ImageBackground style={AppStyles.imageContainer} source={background}>
<KeyboardAvoidingView
style={AppStyles.backgroundCover}
behavior={Platform.OS === "ios" ? "padding" : null}
keyboardVerticalOffset={60}>
<Text style={[AppStyles.lightText, AppStyles.header]}>Sign Up</Text>
<Text style={[AppStyles.errorText]}>{validationMessage}</Text>
<TextInput
style={[AppStyles.textInput, AppStyles.lightTextInput, AppStyles.lightText]}
placeholder='Email'
placeholderTextColor="#BEBEBE"
value={email}
onChangeText={setEmail} />
<TextInput
style={[AppStyles.textInput, AppStyles.lightTextInput, AppStyles.lightText]}
placeholder='Password'
placeholderTextColor="#BEBEBE"
secureTextEntry={true}
value={password}
onChangeText={(value) => validateAndSet(value, confirmPassword, setPassword)} />
<TextInput
style={[AppStyles.textInput, AppStyles.lightTextInput, AppStyles.lightText]}
placeholder='Confirm Password'
placeholderTextColor="#BEBEBE"
secureTextEntry={true}
value={confirmPassword}
onChangeText={(value) => validateAndSet(value, password, setConfirmPassword)} />
<View style={[AppStyles.rowContainer, AppStyles.topMargin]}>
<Text style={AppStyles.lightText}>Already have an account? </Text>
<InlineTextButton text="Login" onPress={() => navigation.popToTop()} />
</View>
<Button title="Sign Up" onPress={signUp} color="#f7b267" />
</KeyboardAvoidingView>
</ImageBackground>
);
}
我不知道為什么這是 hapening 我期待在我單擊注冊按鈕時解決此錯誤后它會創建用戶帳戶
您使用的是 firebase 9 嗎?
你應該這樣做:
import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";
const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// ..
});
您必須將 auth 作為參數發送但不要導入它,而不是像您在示例中看到的那樣使用const auth = getAuth()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.