### Configure robots.txt for Android Digital Asset Links
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
Example `robots.txt` configuration to ensure that web crawlers are allowed to access the `/.well-known/` directory. This is crucial for the discoverability of `assetlinks.json` for Android Digital Asset Links.
```Text
User-agent: *
Allow: /.well-known/
```
--------------------------------
### Clean and Rebuild React Native Project
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
Commands to clean the build artifacts for both Android and iOS projects, often used to resolve persistent build errors.
```Shell
cd android && ./gradlew clean
```
```Shell
cd ios && pod install
```
--------------------------------
### Install React Native Credentials Manager via npm, yarn, or pnpm
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
These commands demonstrate how to add the `react-native-credentials-manager` library to your project using popular JavaScript package managers. Choose the command corresponding to your preferred package manager (npm, yarn, or pnpm) to include the dependency in your `node_modules`.
```Shell
npm install react-native-credentials-manager
```
```Shell
yarn add react-native-credentials-manager
```
```Shell
pnpm add react-native-credentials-manager
```
--------------------------------
### Apple App Site Association File Hosting Path
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
Specifies the required HTTPS URL path where the `apple-app-site-association` file must be hosted. This path is standardized by Apple for discovery of associated domains.
```Text
https://yourdomain.com/.well-known/apple-app-site-association
```
--------------------------------
### Configure Android Digital Asset Links for Passkey Support
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
This JSON configuration defines the Digital Asset Links file (`assetlinks.json`) required to associate your Android application with your website for passkey support. It specifies permissions for handling URLs and getting login credentials, targeting your app's package name and SHA-256 certificate fingerprint. This file must be hosted at `https://your-domain.com/.well-known/assetlinks.json`.
```JSON
[
{
"relation": [
"delegate_permission/common.handle_all_urls",
"delegate_permission/common.get_login_creds"
],
"target": {
"namespace": "android_app",
"package_name": "your.package.name",
"sha256_cert_fingerprints": [
"YOUR_APP_SIGNING_CERTIFICATE_SHA256_FINGERPRINT"
]
}
}
]
```
--------------------------------
### Apple App Site Association (AASA) File Content
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
Defines the JSON structure for the `apple-app-site-association` file, essential for Universal Links and other Apple services. Placeholders `TEAMID` and `com.yourcompany.yourapp` must be replaced with your Apple Developer Team ID and app's bundle identifier respectively.
```JSON
{
"webcredentials": {
"apps": ["TEAMID.com.yourcompany.yourapp"]
}
}
```
--------------------------------
### Install React Native Pdf From Image Library
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-pdf-from-image
Instructions for installing the React Native Pdf From Image library using npm or yarn, and setting up iOS pods for native dependencies.
```Shell
npm install react-native-pdf-from-image
```
```Shell
yarn add react-native-pdf-from-image
```
```Shell
cd ios && pod install
```
--------------------------------
### Add ProGuard Rules for Android Credential Manager
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
These ProGuard rules are necessary if you are using code shrinking in your Android application. They ensure that the `androidx.credentials.playservices` classes, which are part of the Credential Manager library, are not obfuscated or removed, preventing runtime issues. Add these lines to your `android/app/proguard-rules.pro` file.
```ProGuard
-if class androidx.credentials.CredentialManager
-keep class androidx.credentials.playservices.** {
*;
}
```
--------------------------------
### Install React Native Text Touch Highlight Library
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/rn-text-touch-highlight
Instructions for installing the `rn-text-touch-highlight` package and its peer dependencies (`react-native-reanimated`, `react-native-gesture-handler`) using npm or yarn.
```npm
npm install react-native-reanimated
npm install react-native-gesture-handler
npm install rn-text-touch-highlight
```
```yarn
yarn add react-native-reanimated
yarn add react-native-gesture-handler
yarn add rn-text-touch-highlight
```
--------------------------------
### Install React Native Push Down Alert Library
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-pushdown-alert
Commands to install the `react-native-pushdown-alert` library using npm or yarn, providing options for different package managers.
```bash
npm install react-native-pushdown-alert
# or
yarn add react-native-pushdown-alert
```
--------------------------------
### Retrieve Android SHA-1 Signing Certificate Fingerprint
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
Command to execute in your project's root directory to generate a signing report for your Android application. This report includes the SHA-1 fingerprint, which is necessary for configuring Google Sign-In in the Google Cloud Console.
```Shell
cd android && ./gradlew signingReport
```
--------------------------------
### JavaScript Examples for TypeAnimationProps Configuration
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-type-animation
Demonstrates various configurations of `TypeAnimationProps` for a typing animation component, including sequence definition, timing controls, looping, and styling.
```javascript
const animationProps = {
sequence: [
{ text: "Hello, ", typeSpeed: 100 },
{ text: "World!", typeSpeed: 150, delayBetweenSequence: 500 },
],
delayBetweenSequence: 200,
repeat: 2,
blinkSpeed: 400,
cursorStyle: { color: "red" },
};
```
```javascript
const animationProps = {
sequence: [
{ text: "Hello World!", typeSpeed: 100 },
{ text: "Hola World!", typeSpeed: 150, delayBetweenSequence: 500 },
],
delayBetweenSequence: 200,
loop: true,
blinkSpeed: 400,
cursorStyle: { color: "red" },
direction: "back",
};
```
--------------------------------
### Configure iOS Associated Domains for Webcredentials
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
This configuration snippet shows how to add the 'Associated Domains' capability in Xcode for your iOS project. Specifically, it demonstrates adding a `webcredentials` entry for your domain. This is crucial for enabling features like Passkeys and shared credentials between your app and website on iOS.
```APIDOC
webcredentials:yourdomain.com
```
--------------------------------
### Install React Native Type Animation with yarn
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-type-animation
This snippet demonstrates how to install the `react-native-type-animation` library using the yarn package manager. It's an alternative to npm for adding the library as a project dependency.
```bash
yarn add react-native-type-animation
```
--------------------------------
### Install React Native Type Animation with npm
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-type-animation
This snippet shows how to install the `react-native-type-animation` library using the npm package manager. It adds the library as a dependency to your project, making it available for use in your React Native application.
```bash
npm install react-native-type-animation
```
--------------------------------
### React Native Flexible Authentication System Implementation
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/basic-usage
This React Native component (`AuthScreen`) provides a full example of an authentication flow. It integrates `react-native-credentials-manager` to handle user registration with passkeys, sign-in using various methods (passkeys, password, Google, Apple), and user sign-out. It includes platform-specific logic for Google and Apple sign-in and manages UI state based on authentication status.
```javascript
import React, { useState } from "react";
import { View, Button, Text, Platform, Alert } from "react-native";
import {
signUpWithPasskeys,
signUpWithPassword,
signUpWithGoogle,
signIn,
signOut,
} from "react-native-credentials-manager";
// Configuration
const WEB_CLIENT_ID = "YOUR_GOOGLE_WEB_CLIENT_ID";
const DOMAIN = "yourdomain.com";
export default function AuthScreen() {
const [loading, setLoading] = useState(false);
const [user, setUser] = useState(null);
// Helper to generate a random challenge
const generateChallenge = () => {
const array = new Uint8Array(32);
window.crypto.getRandomValues(array);
return btoa(String.fromCharCode.apply(null, Array.from(array)));
};
// Register with passkey
const handlePasskeyRegistration = async () => {
setLoading(true);
try {
const userId = btoa(`user_${Math.random().toString(36).substring(2)}`);
const challenge = generateChallenge();
const request = {
challenge,
rp: { name: "Your App", id: DOMAIN },
user: { id: userId, name: "user@example.com", displayName: "User" },
pubKeyCredParams: [
{ type: "public-key", alg: -7 },
{ type: "public-key", alg: -257 },
],
timeout: 60000,
attestation: "none",
authenticatorSelection: {
authenticatorAttachment: "platform",
requireResidentKey: true,
residentKey: "required",
userVerification: "required",
},
};
const response = await signUpWithPasskeys(request);
// In a real app, you would send this to your server
// await api.registerPasskey(response);
Alert.alert("Success", "Passkey registered successfully");
setUser({ id: userId, type: "passkey" });
} catch (error) {
Alert.alert("Error", `Registration failed: ${error.message}`);
} finally {
setLoading(false);
}
};
// Sign in with any available method
const handleSignIn = async () => {
setLoading(true);
try {
const methods = ["passkeys", "password"];
// Add platform-specific method
if (Platform.OS === "android") {
methods.push("google-signin");
} else {
methods.push("apple-signin");
}
const params = {
passkeys: {
challenge: generateChallenge(),
rpId: DOMAIN,
timeout: 60000,
userVerification: "required",
},
};
if (Platform.OS === "android") {
params.googleSignIn = {
serverClientId: WEB_CLIENT_ID,
autoSelectEnabled: true,
};
} else {
params.appleSignIn = {
requestedScopes: ["fullName", "email"],
};
}
const credential = await signIn(methods, params);
// Handle different credential types
let userData = null;
switch (credential.type) {
case "passkey":
userData = { type: "passkey", verified: true };
break;
case "password":
userData = { type: "password", username: credential.username };
break;
case "google-signin":
userData = {
type: "google",
id: credential.id,
name: credential.displayName,
};
break;
case "apple-signin":
userData = {
type: "apple",
id: credential.id,
email: credential.email,
};
break;
}
setUser(userData);
Alert.alert("Success", `Signed in with ${credential.type}`);
} catch (error) {
Alert.alert("Error", `Sign in failed: ${error.message}`);
} finally {
setLoading(false);
}
};
// Sign out
const handleSignOut = async () => {
setLoading(true);
try {
await signOut();
setUser(null);
Alert.alert("Success", "Signed out successfully");
} catch (error) {
Alert.alert("Error", `Sign out failed: ${error.message}`);
} finally {
setLoading(false);
}
};
return (
{user ? (
<>
Signed in as: {JSON.stringify(user, null, 2)}
>
) : (
<>
{loading && Loading...}
>
)}
);
}
```
--------------------------------
### Sample JavaScript Configuration for PushDownAlertPortal
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-pushdown-alert
This JavaScript example demonstrates how to create a configuration object for the `PushDownAlertPortal` component. It customizes alert display duration, animation timings, queuing behavior, and applies custom styles and icons for success, error, and warning alert types.
```javascript
const config = {
alertDisplayDuration: 4000,
openAnimationDuration: 500,
closeAnimationDuration: 500,
alertQueueBehaviour: 'queue',
titleTextStyle: { fontSize: 18, fontWeight: 'bold', color: '#fff' },
messageTextStyle: { fontSize: 16, color: '#fff' },
successConfig: {
icon: , // Replace with your custom icon component
backgroundColor: '#4CAF50', // Green background for success alerts
},
errorConfig: {
icon: , // Replace with your custom icon component
backgroundColor: '#F44336', // Red background for error alerts
},
warningConfig: {
icon: , // Replace with your custom icon component
backgroundColor: '#FFC107', // Yellow background for warning alerts
},
};
```
--------------------------------
### Retrieve Android Release Build SHA-256 Certificate Fingerprint
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
This `keytool` command is used to extract the SHA-256 certificate fingerprint from your Android release keystore. You need to replace placeholders with your actual keystore file path and alias. This fingerprint is essential for associating your release app with Digital Asset Links for passkey functionality.
```Shell
keytool -list -v -keystore your-keystore.keystore -alias your-key-alias
```
--------------------------------
### Implement React Native Text Touch Highlight Component
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/rn-text-touch-highlight
Demonstrates how to import and use the `HighlightText` component. It shows how to configure various props like `clearHighlightOnTap`, `highlightInitialDelay`, `initialHighlightData`, `lineSpace`, `lineBreakHeight`, text and highlight colors, and event handlers such as `onHighlightStart`, `onHighlightEnd`, and `onHighlightTapped`. It also includes examples of accessing highlighted data and deleting highlights via a ref.
```JavaScript
import { HighlightText } from 'rn-text-touch-highlight';
export default function App() {
const highlightRef: any = React.useRef();
const getHighlightData = () => {
const data = highlightRef.current?.getHighlightedData();
console.log(data);
};
const deleteFun = (id) => {
highlightRef.current?.deleteHighlight(id);
};
return (
{
console.log('hightStart');
}}
onHighlightEnd={(id) => {
console.log('hightEnd', id);
}}
onHighlightTapped={(id, event) => {
console.log('tapped', id, event);
}}
textStyle={{ fontSize: 15 }}
backgroundColor="yellow"
text={'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'}
/>
);
}
```
--------------------------------
### Basic Usage of React Native Pdf From Image
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-pdf-from-image
A basic example demonstrating how to import and use the `createPdf` function to generate a PDF from an array of image paths, with optional paper size customization.
```JavaScript
import { createPdf } from 'react-native-pdf-from-image';
const images = ['path/to/image1.jpg'];
const { filePath } = createPdf({
imagePaths: images,
name: 'myPdf',
paperSize: 'A4', // optional
// optional
customPaperSize: {
height: 300,
width: 300,
},
});
```
--------------------------------
### Retrieve Android Debug Build SHA-256 Certificate Fingerprint
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/installation
This command uses Gradle to generate a signing report for your Android project, allowing you to find the SHA-256 certificate fingerprint for your debug build. The fingerprint is typically located under the 'debugAndroidTest' variant in the report output. This is crucial for configuring Digital Asset Links.
```Shell
cd android && ./gradlew signingReport
```
--------------------------------
### Basic Usage of React Native Type Animation Component
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-type-animation
This example demonstrates how to import and use the `TypeAnimation` component in a React Native application. It showcases a basic sequence of text animations, including text display, delays, and a callback action, with looping enabled and custom styling applied.
```javascript
import { TypeAnimation } from "react-native-type-animation";
const MyComponent = () => {
return (
{
console.log("Finished first two sequences");
}
},
{ text: "One Two Three" },
{ text: "One Two" },
{ text: "One" }
]}
loop
style={{
color: "white",
backgroundColor: "green",
fontSize: 30
}}
/>
);
};
export default MyComponent;
```
--------------------------------
### Implement Combined Authentication Methods in React Native
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/password
Demonstrates how to use `react-native-credentials-manager`'s `signIn` function to support multiple authentication methods simultaneously, such as passkeys, passwords, Google Sign-In (Android), and Apple Sign-In (iOS). The example shows dynamic method selection based on the platform and handling of different credential types returned by the `signIn` operation.
```javascript
import { signIn, Platform } from "react-native-credentials-manager";
async function signInWithMultipleMethods() {
try {
// Dynamically choose sign-in methods based on platform
const signInMethods = ["passkeys", "password"];
// Add platform-specific method
if (Platform.OS === "android") {
signInMethods.push("google-signin");
} else {
signInMethods.push("apple-signin");
}
const credential = await signIn(signInMethods, {
passkeys: {
challenge: "your-base64-challenge",
rpId: "yourdomain.com",
timeout: 60000,
userVerification: "required"
},
googleSignIn:
Platform.OS === "android"
? {
serverClientId: "your-web-client-id",
autoSelectEnabled: true
}
: undefined,
appleSignIn:
Platform.OS === "ios"
? {
requestedScopes: ["fullName", "email"]
}
: undefined
});
// Handle different credential types
switch (credential.type) {
case "password":
// Handle password credential
console.log("Password sign-in:", credential.username);
break;
case "passkey":
// Handle passkey credential
console.log("Passkey sign-in:", credential.authenticationResponseJson);
break;
case "google-signin":
// Handle Google sign-in
console.log("Google sign-in:", credential.idToken);
break;
case "apple-signin":
// Handle Apple sign-in
console.log("Apple sign-in:", credential.idToken);
break;
}
} catch (error) {
console.error("Sign-in failed:", error);
n}
}
```
--------------------------------
### Usage with Old Architecture (Promise-based) in React Native Pdf From Image
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-pdf-from-image
Example demonstrating how to use the `createPdf` function when working with the old React Native architecture, where the function returns a Promise and requires `await` for asynchronous operation.
```JavaScript
import { createPdf } from 'react-native-pdf-from-image';
// Old Architecture
const generatePdf = async () => {
const images = ['path/to/image1.jpg'];
const { filePath } = await createPdf({
imagePaths: images,
name: 'myPdf',
// Optional
paperSize: 'A4',
// Optional
customPaperSize: {
height: 300,
width: 300,
},
});
};
```
--------------------------------
### Handle Password Sign-Up Errors in React Native
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/password
Illustrates robust error handling for password sign-up operations using `signUpWithPassword`. The example includes checks for platform limitations (iOS not supporting manual password storage), specific error message parsing (e.g., 'CANCELLED', 'NO_CREDENTIAL_AVAILABLE'), and a generic fallback for unknown errors, providing clear user feedback.
```javascript
import { signUpWithPassword, Platform } from "react-native-credentials-manager";
async function handlePasswordSignUp(username: string, password: string) {
if (Platform.OS !== "android") {
// Provide a clear message about platform limitations
return {
success: false,
error:
"Manual password storage is not supported on iOS. Please use another authentication method."
};
}
try {
await signUpWithPassword({ username, password });
return { success: true };
} catch (error) {
// Handle specific error types
if (error.message?.includes("CANCELLED")) {
return {
success: false,
error: "Password save operation was cancelled by the user."
};
} else if (error.message?.includes("NO_CREDENTIAL_AVAILABLE")) {
return {
success: false,
error: "No password credentials are available."
};
}
// Generic error handling
return {
success: false,
error: `Failed to save password: ${error.message || "Unknown error"}`
};
}
}
```
--------------------------------
### API Reference: Google Sign-In Parameters for Android (`signUpWithGoogle`)
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/platform-signin
Detailed API documentation for the parameters accepted by the `signUpWithGoogle` function when used on Android. It specifies required fields, data types, and default values for configuring Google Sign-In.
```APIDOC
signUpWithGoogle(options: object): Promise
options:
serverClientId: string (Required) - Your Google Web Client ID
nonce: string (Optional) - Random string for token validation
autoSelectEnabled: boolean (Optional, Default: true) - Auto-select account if only one is available
```
--------------------------------
### API Reference: Apple Sign-In Parameters for iOS (`signUpWithApple`)
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/platform-signin
Detailed API documentation for the parameters accepted by the `signUpWithApple` function when used on iOS. It specifies data types, default values, and options for requesting user information during Apple Sign-In.
```APIDOC
signUpWithApple(options: object): Promise
options:
nonce: string (Optional) - Random string for token validation
requestedScopes: string[] (Optional, Default: ['fullName', 'email']) - Requested user information
```
--------------------------------
### Import PushDownAlertPortal Component
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-pushdown-alert
Imports the `PushDownAlertPortal` component from the `react-native-pushdown-alert` library, which is the entry point for setting up the alert system.
```javascript
import { PushDownAlertPortal } from 'react-native-pushdown-alert';
```
--------------------------------
### Register User with Passkey Authentication
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/basic-usage
Demonstrates how to register a new user using passkeys, a secure, passwordless authentication method. It constructs a `passkeyRequest` object with required WebAuthn parameters like challenge, relying party information, user details, and public key credential types, then calls `signUpWithPasskeys` to initiate the registration process.
```TypeScript
async function registerWithPasskey() {
// Generate a random user ID and encode as base64
const userId = btoa(`user_${Math.random().toString(36).substring(2)}`);
const passkeyRequest = {
challenge: "BASE64_ENCODED_CHALLENGE", // From your server
rp: {
name: "Your App Name",
id: "yourdomain.com",
},
user: {
id: userId,
name: "user@example.com",
displayName: "User Name",
},
pubKeyCredParams: [
{
type: "public-key",
alg: -7, // ES256
},
{
type: "public-key",
alg: -257, // RS256
},
],
timeout: 60000, // 60 seconds
attestation: "none",
excludeCredentials: [], // Existing credentials to exclude
authenticatorSelection: {
authenticatorAttachment: "platform",
requireResidentKey: true,
residentKey: "required",
userVerification: "required",
},
};
try {
const response = await signUpWithPasskeys(
passkeyRequest,
false // preferImmediatelyAvailableCredentials (Android only)
);
// Send the response to your server
console.log("Passkey registration successful:", response);
return response;
} catch (error) {
console.error("Passkey registration failed:", error);
throw error;
}
}
```
--------------------------------
### Implement Multi-Method Sign-In with React Native Credentials Manager
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/platform-signin
This asynchronous function demonstrates how to combine different authentication methods like Passkeys, Password, Google Sign-In (Android), and Apple Sign-In (iOS) using `react-native-credentials-manager`. It dynamically adds platform-specific methods and parameters, then handles the returned credential based on its type.
```JavaScript
import { signIn, Platform } from "react-native-credentials-manager";
async function multiMethodSignIn() {
try {
const methods = ["passkeys", "password"];
// Add platform-specific method
if (Platform.OS === "android") {
methods.push("google-signin");
} else {
methods.push("apple-signin");
}
const params = {
passkeys: {
challenge: "BASE64_ENCODED_CHALLENGE",
rpId: "yourdomain.com",
timeout: 60000,
userVerification: "required",
},
};
// Add platform-specific parameters
if (Platform.OS === "android") {
params.googleSignIn = {
serverClientId: "YOUR_WEB_CLIENT_ID",
autoSelectEnabled: true,
};
} else {
params.appleSignIn = {
requestedScopes: ["fullName", "email"],
};
}
const credential = await signIn(methods, params);
// Handle different credential types
switch (credential.type) {
case "google-signin":
// Handle Google credential
return handleGoogleSignIn(credential);
case "apple-signin":
// Handle Apple credential
return handleAppleSignIn(credential);
default:
// Handle other credential types
return handleOtherCredential(credential);
}
} catch (error) {
console.error("Multi-method sign-in failed:", error);
throw error;
}
}
```
--------------------------------
### Implement Unified Multi-Method User Sign-In
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/basic-usage
This function illustrates a comprehensive sign-in flow that supports multiple authentication methods such as passkeys, passwords, Google Sign-In, and Apple Sign-In. It dynamically adds platform-specific methods based on `Platform.OS` and prepares parameters accordingly. The function then handles different credential types returned by the `signIn` method, logging details or calling specific handlers for each.
```JavaScript
async function signInUser() {
const WEB_CLIENT_ID = "YOUR_GOOGLE_WEB_CLIENT_ID";
try {
// Determine which sign-in methods to offer based on platform
const signInMethods: SignInOption[] = ["passkeys", "password"];
// Add platform-specific method
if (Platform.OS === "android") {
signInMethods.push("google-signin");
} else {
signInMethods.push("apple-signin");
}
// Prepare parameters for sign-in
const params: any = {
// Passkey authentication parameters
passkeys: {
challenge: "BASE64_ENCODED_CHALLENGE", // From your server
timeout: 60000,
userVerification: "required",
rpId: "yourdomain.com",
},
};
// Add platform-specific parameters
if (Platform.OS === "android") {
params.googleSignIn = {
serverClientId: WEB_CLIENT_ID,
autoSelectEnabled: true,
};
} else {
params.appleSignIn = {
requestedScopes: ["fullName", "email"],
};
}
// Perform the sign-in
const credential = await signIn(signInMethods, params);
// Handle different credential types
switch (credential.type) {
case "passkey":
console.log(
"Passkey authentication successful:",
credential.authenticationResponseJson
);
// Send the authentication response to your server for verification
return handlePasskeyAuthentication(
credential.authenticationResponseJson
);
case "password":
console.log("Password authentication successful:", credential.username);
// Verify password with your backend
return handlePasswordAuthentication(
credential.username,
credential.password
);
case "google-signin":
console.log("Google Sign-In successful:", credential.idToken);
// Verify the Google token with your backend
return handleGoogleAuthentication(credential.idToken);
case "apple-signin":
console.log("Apple Sign In successful:", credential.idToken);
// Verify the Apple token with your backend
return handleAppleAuthentication(credential.idToken);
default:
throw new Error(
`Unsupported credential type: ${(credential as any).type}`
);
}
} catch (error) {
// Handle common errors
if (error.message?.includes("CANCELLED")) {
console.log("User cancelled the sign-in process");
} else if (error.message?.includes("NO_CREDENTIAL_AVAILABLE")) {
console.log("No credentials available for the requested methods");
} else {
console.error("Sign-in failed:", error);
}
throw error;
}
}
```
--------------------------------
### Register a New Passkey in React Native
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/passkey
This code snippet demonstrates how to initiate a passkey registration flow for a new user during sign-up. It constructs a `registrationRequest` object containing essential details like the challenge, relying party (RP) information, user data, and public key credential parameters. The `signUpWithPasskeys` function from `react-native-credentials-manager` is then called, and the resulting response is sent to the backend server for verification and storage.
```JavaScript
import { signUpWithPasskeys } from "react-native-credentials-manager";
// Create a registration request
const registrationRequest = {
challenge: "BASE64_ENCODED_CHALLENGE", // Random challenge from your server
rp: {
name: "Your App Name",
id: "yourdomain.com",
},
user: {
id: "BASE64_ENCODED_USER_ID", // User ID from your server
name: "username@example.com",
displayName: "User Name",
},
pubKeyCredParams: [
{
type: "public-key",
alg: -7, // ES256
},
{
type: "public-key",
alg: -257, // RS256
},
],
timeout: 60000, // 60 seconds
attestation: "none",
excludeCredentials: [], // Array of existing credentials to exclude
authenticatorSelection: {
authenticatorAttachment: "platform",
requireResidentKey: true,
residentKey: "required",
userVerification: "required",
},
};
try {
const response = await signUpWithPasskeys(
registrationRequest,
false // preferImmediatelyAvailableCredentials (Android only)
);
// Send the response to your server for verification and storage
await sendToServer("/register-passkey", response);
console.log("Passkey registration successful");
} catch (error) {
console.error("Passkey registration failed:", error);
}
```
--------------------------------
### Passkey Authentication and Registration API Parameters
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/passkey
This section details the required and optional parameters for both passkey registration and authentication requests. It specifies the type, description, and requirement status for each parameter, providing a comprehensive reference for integrating passkey functionality.
```APIDOC
Registration Request Parameters:
- challenge (string, Required): Base64-encoded random challenge from your server
- rp.name (string, Required): Human-readable name of your app/website
- rp.id (string, Required): Domain name of your website (e.g., "example.com")
- user.id (string, Required): Base64-encoded unique user identifier
- user.name (string, Required): Username (often email address)
- user.displayName (string, Required): Human-readable name for display
- pubKeyCredParams (array, Required): Array of supported public key algorithms
- timeout (number, Required): Timeout in milliseconds
- attestation (string, Required): Attestation conveyance preference ("none", "indirect", "direct")
- excludeCredentials (array, Optional): Array of existing credentials to exclude
- authenticatorSelection (object, Optional): Authenticator selection criteria
- authenticatorSelection.authenticatorAttachment (string, Optional): Type of authenticator ("platform" or "cross-platform")
- authenticatorSelection.requireResidentKey (boolean, Optional): Whether to require resident key (discoverable credential)
- authenticatorSelection.residentKey (string, Optional): Resident key requirement ("discouraged", "preferred", "required")
- authenticatorSelection.userVerification (string, Optional): User verification requirement ("discouraged", "preferred", "required")
Authentication Request Parameters:
- challenge (string, Required): Base64-encoded random challenge from your server
- timeout (number, Required): Timeout in milliseconds
- rpId (string, Required): Domain name of your website (e.g., "example.com")
- userVerification (string, Required): User verification requirement ("discouraged", "preferred", "required")
- allowCredentials (array, Optional): Array of credential descriptors to allow (optional)
```
--------------------------------
### Basic Usage of React Native Push Down Alert
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-pushdown-alert
Demonstrates how to integrate and use the `react-native-pushdown-alert` library in a React Native application, including importing components and triggering notifications via a button press.
```javascript
import { PushDownAlertPortal, showNotification} from 'react-native-pushdown-alert';
import { View, Button } from 'react-native';
const MyApp = () => {
return (
);
};
const config = {}
const App = () => {
return (
);
};
```
--------------------------------
### Import React Native Credentials Manager Library
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/basic-usage
Imports essential functions and types from the `react-native-credentials-manager` package, along with the `Platform` module from `react-native` for platform-specific logic. This is the first step to utilize the library's authentication capabilities.
```TypeScript
import {
signUpWithPasskeys,
signUpWithPassword,
signUpWithGoogle,
signUpWithApple,
signIn,
signOut,
type Credential,
type GoogleCredential,
type AppleCredential,
type SignInOption,
} from "react-native-credentials-manager";
import { Platform } from "react-native";
```
--------------------------------
### Implement Cross-Platform Sign-Up with React Native Credentials Manager
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/platform-signin
This asynchronous function demonstrates how to perform platform-specific sign-up using `react-native-credentials-manager`. It conditionally calls `signUpWithGoogle` for Android and `signUpWithApple` for iOS, handling different parameters and returning a standardized credential object. It also includes robust error handling.
```JavaScript
import {
Platform,
signUpWithGoogle,
signUpWithApple,
} from "react-native-credentials-manager";
async function platformSpecificSignUp() {
try {
if (Platform.OS === "android") {
// Android: Google Sign-In
const googleCredential = await signUpWithGoogle({
serverClientId: "YOUR_WEB_CLIENT_ID",
nonce: "OPTIONAL_NONCE_FOR_SECURITY",
autoSelectEnabled: true,
});
return {
type: "google",
token: googleCredential.idToken,
id: googleCredential.id,
user: {
name: googleCredential.displayName,
givenName: googleCredential.givenName,
familyName: googleCredential.familyName,
photo: googleCredential.profilePicture,
},
};
} else {
// iOS: Apple Sign In
const appleCredential = await signUpWithApple({
nonce: "OPTIONAL_NONCE_FOR_SECURITY",
requestedScopes: ["fullName", "email"],
});
return {
type: "apple",
token: appleCredential.idToken,
id: appleCredential.id,
user: {
name: appleCredential.displayName,
givenName: appleCredential.givenName,
familyName: appleCredential.familyName,
email: appleCredential.email,
},
};
}
} catch (error) {
console.error("Platform-specific sign-up failed:", error);
throw error;
}
}
```
--------------------------------
### Authenticate User with Passkey in React Native
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/passkey
This snippet demonstrates how to sign in a user using an existing passkey in a React Native application. It utilizes the `react-native-credentials-manager` library to create an authentication request, handle the `signIn` process, and send the authentication response to a backend server for verification. It includes error handling for failed authentication attempts.
```javascript
import { signIn } from "react-native-credentials-manager";
// Create an authentication request
const authRequest = {
challenge: "BASE64_ENCODED_CHALLENGE", // Random challenge from your server
timeout: 60000, // 60 seconds
userVerification: "required",
rpId: "yourdomain.com",
};
try {
const credential = await signIn(["passkeys"], {
passkeys: authRequest,
});
if (credential.type === "passkey") {
// Send the authentication response to your server for verification
const authResult = await sendToServer(
"/verify-passkey",
credential.authenticationResponseJson
);
console.log("Passkey authentication successful");
}
} catch (error) {
console.error("Passkey authentication failed:", error);
}
```
--------------------------------
### API Reference for showNotification Function
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-pushdown-alert
Documentation for the `showNotification` function, detailing its parameters for triggering various types of alerts (success, error, warning) with custom titles and messages.
```APIDOC
showNotification(parameters: object)
type: string ('success' | 'error' | 'warning') - Type of the alert.
title: string - Title of the alert.
message: string - Message body of the alert.
```
--------------------------------
### Implement User Sign Out with React Native Credentials Manager
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-credentials-manager/platform-signin
This asynchronous function demonstrates how to sign out a user using `react-native-credentials-manager`. It notes that on iOS, this operation is a no-op for Authentication Services and advises handling local state clearance separately.
```JavaScript
import { signOut, Platform } from "react-native-credentials-manager";
async function handleSignOut() {
try {
await signOut();
console.log("Sign out successful");
// Note: On iOS, this is a no-op as Authentication Services
// doesn't provide a sign-out method. You should handle
// sign-out logic in your app separately.
// Clear local auth state
clearLocalAuthState();
} catch (error) {
console.error("Sign out failed:", error);
}
}
```
--------------------------------
### API Reference for PushDownAlertPortal Component
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-pushdown-alert
Documentation for the `PushDownAlertPortal` component, outlining its configurable properties. The `config` prop allows for customizing the alert's behavior and appearance.
```APIDOC
PushDownAlertPortal(props: object)
config: object - Configuration object for customizing alert behavior and appearance.
```
--------------------------------
### API Documentation for createPdf Function
Source: https://docs.benjamineruvieru.com/docs/category/react-native-credentials-manager/react-native-pdf-from-image
Detailed documentation for the `createPdf` function, including its parameters (`imagePaths`, `name`, `paperSize`, `customPaperSize`) and the structure of its return object (`filePath`).
```APIDOC
createPdf(params):
params: object
imagePaths: Array - An array of file paths to the images to include in the PDF.
name: string - The name of the PDF file to be created.
paperSize: string (optional) - The size of the paper for the PDF (e.g., 'A4').
customPaperSize: object (optional) - Custom dimensions for the paper size.
height: number
width: number
Returns: object
filePath: string - The file path to the generated PDF document.
Note: If neither paperSize nor customPaperSize is provided, image dimensions will be used as the PDF paper size.
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.