This boilerplate provides a straightforward setup for integrating Google and Apple authentication into your React Native application using Expo. It utilizes expo-auth-session
for the auth session management and @react-native-async-storage/async-storage
for persisting user data locally.
- Node.js
- Expo CLI
- A Google Cloud Platform account and a configured OAuth2.0 Client ID
-
Clone the Boilerplate
Clone this repository to your local machine to get started.
git clone <repository-url>
-
Install Dependencies
cd <project-directory> npm install
-
Configure Environment Variables
Update the .env file values with your Google Cloud Platform credentials.
EXPO_PUBLIC_IOS_CLIENT_ID=<Your iOS Client ID>
EXPO_PUBLIC_WEB_CLIENT_ID=<Your Web Client ID>
- Update
app.json
Add your application scheme to the app.json file under expo.
"expo": {
"scheme": "your-custom-scheme"
}
-
Running the Appplication iOS Simulator: Run the following command to start your application on an iOS simulator. Make sure you have Xcode installed and configured.
npx expo run:ios
Web To see the application in action on a web browser, you do not need any additional setup. Just run:
npx expo start --web --https
The boilerplate includes an authentication context (AuthProvider
) that provides userInfo
and promptAsync
to the components. You can initiate the sign-in process using the "Sign in with Google" button. The user information will be displayed on the screen upon successful authentication.
AuthProvider
: Context provider for authentication. It encapsulates the authentication logic and state.useAuth
: Custom hook to access the authentication context.
Ensure you follow best practices for storing and managing your credentials. Do not hardcode your Google Client IDs or any sensitive information within your application's codebase.
- If you encounter issues with authentication or redirection, verify your
app.json
scheme and.env
configuration. - For iOS-specific issues, ensure you've set up your iOS Client ID correctly in the Google Cloud Console and
.env
file.