如何解决在 React Native 应用程序中使用 Firebase 身份验证时,auth.default.signInWithEmailAndPassword 不是函数
我目前正在尝试在我的 React Native 应用程序中使用“signInWithEmailAndPassword”。这是在上下文文件中完成的,并直接从我的登录屏幕调用。我目前正在使用 iOS 对此进行测试。
但是,每次尝试打开屏幕时,都会出现以下错误:
错误似乎发生在我的 SignInScreen 中,但我假设这是因为我正在调用发生错误的上下文。
作为参考,我有:
- 下载并保存了我的 GoogleService-Info.plist 文件
- 将配置代码添加到我的 AppDelegate.m 文件
- 安装了@react-native-firebase/app 和@react-native-firebase/auth 包,pod 也安装了它们
所以我相信我的 Firebase 应该能按预期工作......所以我认为这一定是导入错误,但我尽可能地遵循了 Firebase React Native 文档。
这是我的代码。
登录屏幕:
const SignInScreen = ({navigation}) => {
const {signIn} = useContext(AuthContext);
const [email,setEmail] = useState('');
const [password,setPassword] = useState('');
return (
<View style={styles.parent}>
<View style={styles.mainView}>
<SubLemioLogo />
<Heading title="Sign in to your account" />
<SubHeading content="This email and password is what you used when you signed up" />
<Input
placeholder="Enter email"
inputValue={email}
inputText={text => setEmail(text)}
capitalize="none"
correct={false}
/>
<Input
placeholder="Enter password"
inputValue={password}
inputText={text => setPassword(text)}
capitalize="none"
correct={false}
secure={true}
/>
</View>
<View style={styles.subView}>
<CtaButton
text="Continue"
onPressFunction={signIn(email,password,navigation)}
/>
</View>
</View>
);
};
我的上下文文件:
import * as firebase from '@react-native-firebase/app';
import auth from '@react-native-firebase/auth';
export const AuthContext = React.createContext();
export const AuthProvider = ({children}) => {
const [user,setUser] = useState([]);
const signIn = ({email,navigation}) => {
return auth.signInWithEmailAndPassword(email,password)
.then(() => {
console.log('Successfully signed in.');
navigation.navigate('Dashboard');
})
.catch(error => {
console.log(error);
});
};
return (
<AuthContext.Provider value={{user,signIn}}>
{children}
</AuthContext.Provider>
)
}
任何反馈将不胜感激。
解决方法
从 v5 开始,firebase 包用例已更改。
尝试使用 auth().signInWithEmailAndPassword(email,password)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。