@aws-amplify/ui-react-native package is currently on version 2. Working with@aws-amplify/ui-react-native version 1 or earlier? See our migration guide.The Authenticator component adds complete authentication flows
to your application with minimal boilerplate.
Quick start
Setup with Amplify Gen 2 backend
To get up and running with the Authenticator, follow the Amplify Gen2 quickstart guide.
Setup with Amplify Gen 1 backend
To setup Amplify using the Gen1 CLI, follow the steps below:
Step 1. Configure backend
The Authenticator works seamlessly with the Amplify CLI to automatically work with your backend.
First, update @aws-amplify/cli with npm or yarn
if you're using a version before 6.4.0:
npm install -g @aws-amplify/cli@latestyarn global add @aws-amplify/cli@latestNow that you have the Amplify CLI installed, you can set up your Amplify project by running amplify init in your project's root directory. Then run amplify add auth and follow the prompts to add authentication to your backend configuration.
If you have an existing backend, run amplify pull to sync your aws-exports.js with your cloud backend.
You should now have an aws-exports.js file in your src/ directory with your latest backend configuration.
Step 2. Install dependencies
npm install @aws-amplify/ui-react-native aws-amplify @aws-amplify/react-native react-native-safe-area-context @react-native-community/netinfo @react-native-async-storage/async-storage react-native-get-random-valuesyarn add @aws-amplify/ui-react-native aws-amplify @aws-amplify/react-native react-native-safe-area-context @react-native-community/netinfo @react-native-async-storage/async-storage react-native-get-random-valuesImportant note for integration with React Native projects using version 0.74 or below
react-native-safe-area-context are designed to be compatible with specific React Native versions.0.74 or below, you must install version4.x of react-native-safe-area-context.npm install react-native-safe-area-context@^4.2.5If your project will support Federated Sign In using the React Native Authenticator the @aws-amplify/rtn-web-browser package is also required:
npm install @aws-amplify/rtn-web-browserImportant note for integration with React Native projects using version 0.72 or below
0.72 or below@aws-amplify/react-native and @aws-amplify/rtn-web-browser require a minimum iOS deployment target of 13.0, open the Podfile located in the ios directory and update the target value:
- platform :ios, min_ios_version_supported
+ platform :ios, 13.0
Then install the iOS cocoapods by running:
npx pod-installnpx pod-installStep 3. Add the Authenticator
The quickest way to get started is by wrapping your application with the Authenticator component.
Once an end-user has created an account & signed in, the underlying component is rendered with access to the user.
You can use the Authenticator component directly, or wrap your app in withAuthenticator
Higher-Order Component:
import React from 'react';
import { Button } from 'react-native';
import { Authenticator, useAuthenticator } from '@aws-amplify/ui-react-native';
import { Amplify } from 'aws-amplify';
import config from './aws-exports';
Amplify.configure(config);
function SignOutButton() {
const { signOut } = useAuthenticator();
return <Button title="Sign Out" onPress={signOut} />;
}
function App() {
return (
<Authenticator.Provider>
<Authenticator>
<SignOutButton />
</Authenticator>
</Authenticator.Provider>
);
}
export default App;
import React from 'react';
import { Button } from 'react-native';
import { Amplify } from 'aws-amplify';
import {
useAuthenticator,
withAuthenticator,
} from '@aws-amplify/ui-react-native';
import awsconfig from './aws-exports';
Amplify.configure(awsconfig);
function SignOutButton() {
const { signOut } = useAuthenticator();
return <Button onPress={signOut} title="Sign Out" />;
}
function App() {
return <SignOutButton />;
}
export default withAuthenticator(App);