A Simple React Native module for implementing Google Sign-In (SSO) functionality in your React Native applications uses Google Sign-In SDK on iOS and Credential Manager on Android.
- React Native v0.78.0 or higher
- Node 18.0.0 or higher
[!IMPORTANT]
To useGoogle Sign-In Button
you need to install React Native version v0.78.0 or higher.
bun add react-native-nitro-google-sso react-native-nitro-modules
# or
npm install react-native-nitro-google-sso
# or
yarn add react-native-nitro-google-sso
Before using this module, you need to:
- Set up a Google Cloud Project
- Configure OAuth 2.0 credentials
- Get your iOS Client ID and Web Client ID from the Google Cloud Console
First, you need to configure the module with your Google credentials. It's recommended to do this in your app's entry point:
import NitroGoogleSSO from 'react-native-nitro-google-sso'
// Configure the module
NitroGoogleSSO.configure({
iosClientId: 'YOUR_IOS_CLIENT_ID',
webClientId: 'YOUR_WEB_CLIENT_ID',
nonce: 'YOUR_NONCE', // Optional security nonce
})
To sign in with Google:
try {
const user = await NitroGoogleSSO.signIn()
if (user) {
console.log('User signed in:', user)
} else {
console.log('User cancelled sign in')
}
} catch (error) {
console.error('Sign in error:', error)
}
To sign in with Google using the one tap sign in:
try {
const user = await NitroGoogleSSO.oneTapSignIn()
if (user) {
console.log('User signed in:', user)
} else {
console.log('User cancelled sign in')
}
} catch (error) {
console.error('Sign in error:', error)
}
To get the currently signed-in user's information:
try {
const user = await NitroGoogleSSO.getCurrentUser()
if (user) {
console.log('Current user:', user)
} else {
console.log('No user is signed in')
}
} catch (error) {
console.error('Error getting current user:', error)
}
To sign out the current user:
try {
await NitroGoogleSSO.signOut()
console.log('User signed out successfully')
} catch (error) {
console.error('Sign out error:', error)
}
interface NitroGoogleSSOConfig {
iosClientId: string
webClientId: string
nonce?: string
hostedDomain?: string
}
The user information returned by the sign-in process. The exact structure depends on the information requested during the sign-in process.
This module supports both iOS and Android platforms.
Always wrap the module's methods in try-catch blocks as they may throw errors in various scenarios:
- Network connectivity issues
- Invalid configuration
- User cancellation
- Authentication failures
- Configure the module as early as possible in your app's lifecycle
- Handle all potential errors appropriately
- Implement proper state management for the user's authentication status
- Store sensitive credentials securely
- Implement proper error recovery mechanisms
Bootstrapped with create-nitro-module.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
MIT