auth.default.signInWithEmailAndPassword 在 React Native 应用程序中使用 Firebase Auth 时不是函数
auth.default.signInWithEmailAndPassword is not a function when using Firebase Auth in React Native app
我目前正在尝试在我的 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, password, 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)
我目前正在尝试在我的 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, password, 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)