firebase登录验证
Authentication allows us to secure our apps, or limit access for non-user members. Authentication can also be used, for example, to limit access to a paid service or specific service.
身份验证使我们能够保护我们的应用程序安全,或限制非用户成员的访问权限。 身份验证也可以用于例如限制对付费服务或特定服务的访问。
That's just one example of how authentication can be in your app. Today we will add authentication to a React Native app using Firebase.
那只是在您的应用程序中如何进行身份验证的一个示例。 今天,我们将使用Firebase将身份验证添加到React Native应用程序。
1安装react-native-firebase (1 Installing react-native-firebase)
The first thing we do is install and initialize Firebase inside our app. In React Native we need to use a Firebase Container for React Native. We are going to use react-native-firebase.
我们要做的第一件事是在应用程序内部安装并初始化Firebase。 在React Native中,我们需要为Fire Native使用Firebase容器。 我们将使用react-native-firebase 。
If you are about to start a new React Native app from scratch and you would like to use Firebase, you are lucky - you can install react-native-firebase pre-integrated using the React Native CLI.
如果您将要从头开始一个新的React Native应用程序,并且想使用Firebase,那么您很幸运-您可以安装使用React Native CLI预集成的react-native-firebase。
//
npx @react-native-community/cli init --template=@react-native-firebase/template authenticationFirebase
//** source: https://invertase.io/oss/react-native-firebase/quick-start/new-project
Then just install the pod for iOS by running the following command inside the root directory of your app.
然后,只需在应用程序的根目录中运行以下命令,即可为iOS安装pod。
cd ios && pod install
If you are having issues installing a new project with Firebase please refer to react-native-firebase docs
如果您在使用Firebase安装新项目时遇到问题,请参阅react-native-firebase文档
将react-native-firebase添加到现有项目 (Adding react-native-firebase to an existing project)
Install the react-native-firebase
package using yarn or npm
使用yarn或npm安装react-native-firebase
软件包
yarn add @react-native-firebase/app
or:
要么:
npm install @react-native-firebase/app
Then install pods for iOS.
然后安装iOS的Pod。
shell cd ios && pod install
shell cd ios && pod install
运行应用 (Running the app)
For iOS, there are two ways to do it: I personally use Xcode, as it gives me a clear idea if something went wrong and the build failed.
![Xcode](https://www.freecodecamp.org/news/how-to-add-authentication-to-react-native-in-three-steps-using-firebase/build-xcode.gif)
对于iOS,有两种方法可以实现:我个人使用Xcode,因为它可以使我清楚地知道出了什么问题并且构建失败。
Always make sure the package is running - hit yarn start
to start the app.
始终确保程序包正在运行- yarn start
打yarn start
以启动应用程序。
The second way to run the app on iOS is running the react-native run-ios command - and that's it.
在iOS上运行应用程序的第二种方法是运行re