Types
This document describes the TypeScript types and enums available in react-native-oauth-essentials. These types provide
strong typing for authentication credentials and configuration options.
Configuration Types
GoogleSignInOptions
Configuration options for customizing the Google sign-in behavior.
Properties:
authorizedAccounts(boolean, optional) - Android only. When enabled, allows users to select from previously authorized Google accounts on the deviceautoSelectEnabled(boolean, optional) - Android only. Automatically selects a Google account if only one authorized account is available, skipping the account picker UI
Example:
const options: GoogleSignInOptions = {
authorizedAccounts: true, // Android only
autoSelectEnabled: false, // Android only
};
PasskeyOptions
Configuration options for creating or retrieving passkeys.
Properties:
requestJson(string, required) - JSON string containingPublicKeyCredentialCreationOptions(for creation) orPublicKeyCredentialRequestOptions(for retrieval) as defined by the WebAuthn standardpreferImmediatelyAvailableCredentials(boolean, optional) - Android only. Whentrue, only show passkeys that are immediately available without requiring additional user interactionisConditional(boolean, optional) - Android only. Whentrue, allows conditional UI for passkey selection
Example:
const options: PasskeyOptions = {
requestJson: JSON.stringify({
challenge: 'base64-encoded-challenge',
rp: { name: 'Your App', id: 'yourapp.com' },
user: {
id: 'base64-user-id',
name: 'user@example.com',
displayName: 'User Name'
},
pubKeyCredParams: [{ type: 'public-key', alg: -7 }],
timeout: 60000,
authenticatorSelection: {
authenticatorAttachment: 'platform',
requireResidentKey: true,
userVerification: 'required'
}
}),
preferImmediatelyAvailableCredentials: true, // Android only
isConditional: false, // Android only
};
Credential Result Types
These types represent the authentication results returned by different sign-in methods. Each credential type includes a
type discriminator and method-specific data.
PasswordCredentialResult
Represents the result of password-based authentication.
Properties:
type- AlwaysCredentialsType.PASSWORDdata- Object containing:username(string) - The authenticated user's username or email addresspassword(string) - The user's password
Example:
const credential: PasswordCredentialResult = {
type: CredentialsType.PASSWORD,
data: {
username: 'user@example.com',
password: 'securepassword123',
},
};
GoogleIdCredentialResult
Represents the result of Google OAuth authentication.
Properties:
type- AlwaysCredentialsType.GOOGLE_IDdata- Object containing:id(string) - Unique Google user identifieridToken(string) - JWT token for verifying the user's identity with your backenddisplayName(string) - User's full display namegivenName(string) - User's first namefamilyName(string) - User's last nameprofilePictureUri(string | null, optional) - URL to the user's profile picture, if availablephoneNumber(string | null, optional) - User's phone number, if shared and available
Example:
const credential: GoogleIdCredentialResult = {
type: CredentialsType.GOOGLE_ID,
data: {
id: '1234567890',
idToken: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...',
displayName: 'John Doe',
givenName: 'John',
familyName: 'Doe',
profilePictureUri: 'https://lh3.googleusercontent.com/...',
phoneNumber: '+1234567890',
},
};
AppleIdCredentialResult
Represents the result of Apple ID authentication on iOS.
Properties:
type- AlwaysCredentialsType.APPLE_IDdata- Object containing:idToken(string) - JWT ID tokenauthorizationCode(string) - Authorization code for backend verificationuser(string) - Unique user identifier (stable across app reinstalls)email(string) - User's email address (only provided on first sign-in)fullName(string) - User's full name (only provided on first sign-in)likelyReal(boolean) - Indicates if the user is likely a real person
Platform: iOS only
Important: email and fullName are only provided on the first sign-in. The library caches these values, but you should store them in your backend on first authentication.
Example:
const credential: AppleIdCredentialResult = {
type: CredentialsType.APPLE_ID,
data: {
idToken: 'eyJraWQiOiJlWGF1bm1MIiwiYWxnIjoiUlMyNTYifQ...',
authorizationCode: 'c1234567890abcdef...',
user: '000123.abc456def789.0123',
email: 'user@privaterelay.appleid.com',
fullName: 'John Appleseed',
likelyReal: true,
},
};
WebAppleIdCredentialResult
Represents the result of Apple ID authentication on Android (browser-based flow).
Properties:
type- AlwaysCredentialsType.WEB_APPLE_IDdata- Object containing:url(string) - Full redirect URL from the browserscheme(string | null) - URL scheme (e.g., "myapp")host(string | null) - URL hostpath(string | null) - URL pathquery(string | null) - URL query parameters containing authorization code
Platform: Android only
Note: You need to parse the query string to extract the authorization code, then send it to your backend for token exchange.
Example:
const credential: WebAppleIdCredentialResult = {
type: CredentialsType.WEB_APPLE_ID,
data: {
url: 'myapp://auth/callback?code=c1234567890abcdef&state=xyz',
scheme: 'myapp',
host: 'auth',
path: '/callback',
query: 'code=c1234567890abcdef&state=xyz',
},
};
// Extract authorization code from query
const params = new URLSearchParams(credential.data.query || '');
const authCode = params.get('code');
PassKeyCredentialResult
Represents the result of passkey creation or retrieval.
Properties:
type- AlwaysCredentialsType.PASSKEYdata(string) - JSON string containing the platform public key credential response as defined by the WebAuthn standard
Example:
const credential: PassKeyCredentialResult = {
type: CredentialsType.PASSKEY,
data: '{"id":"base64-credential-id","rawId":"...","response":{...},"type":"public-key"}',
};
// Parse the credential data
const passkeyData = JSON.parse(credential.data);
console.log('Passkey ID:', passkeyData.id);
CancelledCredentialResult
Represents the result when the user cancels the authentication flow.
Properties:
type- AlwaysCredentialsType.CANCELLEDdata- Alwaysnull
Note: This is not an error - it simply indicates the user dismissed the authentication UI. Your app should handle this gracefully, typically by showing alternative sign-in options.
Example:
const credential: CancelledCredentialResult = {
type: CredentialsType.CANCELLED,
data: null,
};
// Handle cancellation
if (credential.type === CredentialsType.CANCELLED) {
console.log('User cancelled sign-in');
showAlternativeSignInOptions();
}
Enumerations
CredentialsType
Enum defining the available credential types for discriminating between different authentication results.
Values:
GOOGLE_ID- Google OAuth credentialPASSWORD- Username and password credentialAPPLE_ID- Apple ID credential (iOS native)WEB_APPLE_ID- Apple ID credential (Android browser-based)CANCELLED- User cancelled the authentication flowPASSKEY- Passkey (WebAuthn/FIDO2) credential
Usage:
import { CredentialsType } from 'react-native-oauth-essentials';
// Type narrowing example
function handleCredential(
credential: GoogleIdCredentialResult | PasswordCredentialResult | AppleIdCredentialResult | CancelledCredentialResult
) {
switch (credential.type) {
case CredentialsType.GOOGLE_ID:
console.log('Google user:', credential.data.displayName);
break;
case CredentialsType.PASSWORD:
console.log('Password login:', credential.data.username);
break;
case CredentialsType.APPLE_ID:
console.log('Apple ID login:', credential.data.user);
break;
case CredentialsType.WEB_APPLE_ID:
console.log('Android Apple ID redirect:', credential.data.url);
break;
case CredentialsType.CANCELLED:
console.log('User cancelled');
break;
case CredentialsType.PASSKEY:
console.log('Passkey:', JSON.parse(credential.data).id);
break;
}
}
CredentialError
Enum defining possible error codes that may be thrown during authentication operations.
Values:
NO_PLAY_SERVICES_ERROR- Google Play Services is not available or not installed on the device (Android only)NO_ACTIVITY_ERROR- No Android activity context is available to perform the authentication flow (Android only)INVALID_RESULT_ERROR- The authentication result received from the provider is invalid or malformed (Both platforms)
Usage:
import { googleSignIn, CredentialError } from 'react-native-oauth-essentials';
try {
const credential = await googleSignIn('YOUR_WEB_CLIENT_ID');
} catch (error) {
if (error.code === CredentialError.NO_PLAY_SERVICES_ERROR) {
console.error('Please install Google Play Services');
} else if (error.code === CredentialError.NO_ACTIVITY_ERROR) {
console.error('Activity context not available');
} else if (error.code === CredentialError.INVALID_RESULT_ERROR) {
console.error('Invalid authentication result');
} else {
console.error('Unknown error:', error);
}
}
Type Guards
You can use TypeScript type guards for better type safety:
import { CredentialsType, type GoogleIdCredentialResult } from 'react-native-oauth-essentials';
function isGoogleCredential(credential: any): credential is GoogleIdCredentialResult {
return credential.type === CredentialsType.GOOGLE_ID;
}
// Usage
const credential = await googleSignIn('...');
if (isGoogleCredential(credential)) {
// TypeScript knows credential is GoogleIdCredentialResult
console.log(credential.data.idToken);
}