Nowadays in mobile apps most apps are using social login for authentication of users. Integrating social sign-in options like Apple, Google, and Facebook into your React Native app can enhance the user experience by providing easy and quick authentication methods. In this guide, we will walk you through the steps to implement social sign-in using a single SDK. This tutorial includes all the necessary configurations and setup details for both iOS and Android platforms.
First, you need to install the required packages. You can do this using either npm or yarn:
npm install rn-social-login react-native-fbsdk-next @invertase/react-native-apple-authentication @react-native-google-signin/google-signin
OR
yarn add rn-social-login react-native-fbsdk-next @invertase/react-native-apple-authentication @react-native-google-signin/google-signin
Next, install the necessary CocoaPods:
cd ios && pod install && cd ..
To use Google Sign-In in your app, you’ll need to set up your project in the Google Developer Console and obtain OAuth 2.0 Client IDs for Android, iOS, and Web. Here’s how you can do it:
🔷 Obtaining iOS Client ID
Go to Google API Console:
Create a New Project:
Enable APIs and Services:
Configure OAuth Consent Screen:
Create iOS OAuth Client ID:
🔷 Registering an Android App with OAuth Client ID
Create Android OAuth Client ID:
🔷 Generating SHA-1 Certificate Fingerprint
Using Keytool:
keytool -list -v -keystore YOUR_RELEASE_KEY_PATH -alias YOUR_RELEASE_KEY_ALIAS -storepass YOUR_KEYSTORE_PASSWORD -keypass YOUR_KEY_PASSWORD
🔷 Obtaining Web Client ID
Create Web OAuth Client ID:
Now we will configure Google Sign-In in React Native and implement the configuration for both Android and iOS.
1. Download the Configuration File: Download google-services.json from Firebase and place it in the android/app directory.
2. Update android/build.gradle:
buildscript {
ext {
buildToolsVersion = "a.b.c"
minSdkVersion = x
compileSdkVersion = y
targetSdkVersion = z
googlePlayServicesAuthVersion = "20.7.0"
}
dependencies {
classpath 'com.google.gms:google-services:4.4.0'
}
}
3. Update android/app/build.gradle:
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
apply plugin: 'com.google.gms.google-services'
To use the sign-in with Facebook in a mobile app you need to have a facebook developer account. You can follow below steps to create an account in Facebook developer account and after that you can create an app in that and do the configuration.
To access Facebook Sign-In in a mobile app, we need to configure it in React Native as well as in the Android and iOS sides.
mavenCentral()
implementation 'com.facebook.android:facebook-android-sdk:latest.release'
<string name="facebook_app_id">1234</string> <string name="facebook_client_token">56789</string>
<uses-permission android:name="android.permission.INTERNET"/> ... <application android:label="@string/app_name" ...> ... <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/> <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/> ... </application>
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fbAPP-ID</string> </array> </dict> </array> <key>FacebookAppID</key> <string>APP-ID</string> <key>FacebookClientToken</key> <string>CLIENT-TOKEN</string> <key>FacebookDisplayName</key> <string>APP-NAME</string>
<key>LSApplicationQueriesSchemes</key> <array> <string>fbapi</string> <string>fb-messenger-share-api</string> </array>
<dict> ... <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fb123456789</string> <!-- Replace with your AppID --> </array> </dict> </array> <key>FacebookAppID</key> <string>123456789</string> <!-- Replace with your AppID --> <key>FacebookClientToken</key> <string>abcd1234efgh5678ijkl</string> <!-- Replace with your Client Token --> <key>FacebookDisplayName</key> <string>MyAppName</string> <!-- Replace with your App Name --> <key>LSApplicationQueriesSchemes</key> <array> <string>fbapi</string> <string>fb-messenger-share-api</string> </array> ... </dict>
Implementing Apple Sign-In in React Native involves several steps, including setting up your Apple developer account, configuring your app in the Apple Developer portal, and integrating the Apple Sign-In functionality in your React Native app.
Enroll in the Apple Developer Program:
Create an App ID:
Create a Key for Sign-In with Apple:
To enable social sign-ins (Google, Facebook, and Apple) in your React Native project, you’ll need to update your AppDelegate.m file. Follow these steps to set up your app for these integrations properly.
First, import the required headers at the top of your AppDelegate.m file. These imports include the SDKs for Google Sign-In, Facebook, and the necessary modules.
#import <RNGoogleSignin/RNGoogleSignin.h>
#import <React/RCTLinkingManager.h>
#import <AuthenticationServices/AuthenticationServices.h>
#import <SafariServices/SafariServices.h>
#import <FBSDKCoreKit/FBSDKCoreKit-Swift.h>
#import <GoogleSignIn/GoogleSignIn.h>
Inside the didFinishLaunchingWithOptions method, add the following code to initialize the Facebook SDK. This is crucial for the Facebook login to work properly.
// Initialize Facebook SDK
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
Add the following method to handle URL schemes. This method will ensure that the appropriate SDK processes the URL when the app is opened via a URL scheme, which is common in OAuth flows.
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id>
*)options
{
// Handle URL for Google Sign-In
if ([GIDSignIn.sharedInstance handleURL:url]) {
return YES;
}
// Handle URL for React Native Linking
if ([RCTLinkingManager application:app openURL:url
options:options]) {
return YES;
}
// Handle URL for Facebook Sign-In
if ([[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options]) {
return YES;
}
return NO;
}
Here’s an example of how to use the rn-social-login component in your app:
import type { User } from '@react-native-google-signin/google-signin';
import * as React from 'react';
import { Alert, StyleSheet, Text, View } from 'react-native';
import {
SocialLogin,
type FacebookSignInProps,
type SocialLoginHandle,
type AppleSignInProps,
} from 'rn-social-login';
export default function App() {
// Create a ref for the SocialLogin component
const socialLoginRef = React.useRef<SocialLoginHandle>(null);
// Initialize social logins on component mount
React.useEffect(() => {
socialLoginRef?.current?.initSocialLogins({
iosClientId: '<YOUR_IOS_CLIENT_ID>',
webClientId: 'YOUR_WEB_CLIENT_ID',
});
}, []);
/**
* Callback function for successful Google sign-in.
* @param userInfo - Information about the signed-in user.
*/
const onGoogleSuccess = (userInfo: User) => {
console.log('Google login success', userInfo);
Alert.alert('Social Login', 'Google login success.');
};
/**
* Callback function for Google sign-in error.
* @param error - Error object.
*/
const onGoogleError = (error: any) => {
console.log('Google login error', error);
};
/**
* Callback function for successful Facebook sign-in.
* @param token - Access token from Facebook.
* @param currentProfile - Current user profile from Facebook.
*/
const onFacebookSuccess = ({
token,
currentProfile,
}: FacebookSignInProps) => {
console.log('Facebook login token', token);
console.log('Facebook login profile', currentProfile);
Alert.alert('Social Login', 'Facebook login success.');
};
/**
* Callback function for Facebook sign-in error.
* @param error - Error object.
*/
const onFacebookError = (error: any) => {
console.log('Facebook login error', error);
};
/**
* Callback function for successful Apple sign-in.
* @param appleAuthRequestResponse - Response from Apple authentication request.
* @param credentialState - State of the Apple credential.
*/
const onAppleSuccess = ({
appleAuthRequestResponse,
credentialState,
}: AppleSignInProps) => {
console.log(
'Apple login appleAuthRequestResponse',
appleAuthRequestResponse
);
console.log('Apple login credentialState', credentialState);
Alert.alert('Social Login', 'Apple login success.');
};
/**
* Callback function for Apple sign-in error.
* @param error - Error object.
*/
const onAppleError = (error: any) => {
console.log('Apple login error', error);
};
return (
<View style={styles.container}>
<Text style={styles.title}>{'Login With'}</Text>
<SocialLogin
ref={socialLoginRef}
onGoogleSignInSuccess={onGoogleSuccess}
onGoogleSignInError={onGoogleError}
signOutGoogleSignBeforeLogin
onFacebookSignInSuccess={onFacebookSuccess}
onFacebookSignInError={onFacebookError}
onAppleSignInSuccess={onAppleSuccess}
onAppleSignInError={onAppleError}
/>
</View>
);
}
/** Styles for the App component */
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'white',
},
box: {
width: 60,
height: 60,
marginVertical: 20,
},
title: {
fontSize: 16,
color: 'black',
marginBottom: 10,
fontWeight: '700',
},
});
This blog has detailed integrating social login (Apple, Google, Facebook) using a single SDK. This SDK streamlines the integration of Google, Facebook, and Apple sign-ins into your app, reducing complexity and saving time. By following the step-by-step guide, you’ll configure each social login, create necessary developer accounts, and implement the required code seamlessly. This approach not only simplifies the login process but also improves user experience by providing familiar authentication options.
The team at Mindbowser was highly professional, patient, and collaborative throughout our engagement. They struck the right balance between offering guidance and taking direction, which made the development process smooth. Although our project wasn’t related to healthcare, we clearly benefited...
Founder, Texas Ranch Security
Mindbowser played a crucial role in helping us bring everything together into a unified, cohesive product. Their commitment to industry-standard coding practices made an enormous difference, allowing developers to seamlessly transition in and out of the project without any confusion....
CEO, MarketsAI
I'm thrilled to be partnering with Mindbowser on our journey with TravelRite. The collaboration has been exceptional, and I’m truly grateful for the dedication and expertise the team has brought to the development process. Their commitment to our mission is...
Founder & CEO, TravelRite
The Mindbowser team's professionalism consistently impressed me. Their commitment to quality shone through in every aspect of the project. They truly went the extra mile, ensuring they understood our needs perfectly and were always willing to invest the time to...
CTO, New Day Therapeutics
I collaborated with Mindbowser for several years on a complex SaaS platform project. They took over a partially completed project and successfully transformed it into a fully functional and robust platform. Throughout the entire process, the quality of their work...
President, E.B. Carlson
Mindbowser and team are professional, talented and very responsive. They got us through a challenging situation with our IOT product successfully. They will be our go to dev team going forward.
Founder, Cascada
Amazing team to work with. Very responsive and very skilled in both front and backend engineering. Looking forward to our next project together.
Co-Founder, Emerge
The team is great to work with. Very professional, on task, and efficient.
Founder, PeriopMD
I can not express enough how pleased we are with the whole team. From the first call and meeting, they took our vision and ran with it. Communication was easy and everyone was flexible to our schedule. I’m excited to...
Founder, Seeke
We had very close go live timeline and Mindbowser team got us live a month before.
CEO, BuyNow WorldWide
If you want a team of great developers, I recommend them for the next project.
Founder, Teach Reach
Mindbowser built both iOS and Android apps for Mindworks, that have stood the test of time. 5 years later they still function quite beautifully. Their team always met their objectives and I'm very happy with the end result. Thank you!
Founder, Mindworks
Mindbowser has delivered a much better quality product than our previous tech vendors. Our product is stable and passed Well Architected Framework Review from AWS.
CEO, PurpleAnt
I am happy to share that we got USD 10k in cloud credits courtesy of our friends at Mindbowser. Thank you Pravin and Ayush, this means a lot to us.
CTO, Shortlist
Mindbowser is one of the reasons that our app is successful. These guys have been a great team.
Founder & CEO, MangoMirror
Kudos for all your hard work and diligence on the Telehealth platform project. You made it possible.
CEO, ThriveHealth
Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.
CEO, SMILINGMIND
They were a very responsive team! Extremely easy to communicate and work with!
Founder & CEO, TotTech
We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.
Co-Founder, TEAM8s
Mindbowser was very helpful with explaining the development process and started quickly on the project.
Executive Director of Product Development, Innovation Lab
The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.
Co-Founder, Vesica
Mindbowser is professional, efficient and thorough.
Consultant, XPRIZE
Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.
Founder, S.T.A.R.S of Wellness
Mindbowser was great; they listened to us a lot and helped us hone in on the actual idea of the app. They had put together fantastic wireframes for us.
Co-Founder, Flat Earth
Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.
Founder, Child Life On Call
The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!
CEO, SDOH2Health LLC
Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.
CEO, Stealth Startup
Mindbowser was an excellent partner in developing my fitness app. They were patient, attentive, & understood my business needs. The end product exceeded my expectations. Thrilled to share it globally.
Owner, Phalanx
Mindbowser's expertise in tech, process & mobile development made them our choice for our app. The team was dedicated to the process & delivered high-quality features on time. They also gave valuable industry advice. Highly recommend them for app development...
Co-Founder, Fox&Fork