โœจWorks out of the box guarantee. If you face any issue at all, hit us up on Telegram and we will write the integration for you.
logoReclaim Protocol Docs

Frontend Example

This guide will walk you through the fundamental steps to integrate Reclaim's proof verification system into your React application.

Prerequisites

Before implementing Reclaim verification in your React application, ensure you have:

โš ๏ธ Security Critical: Your Application Secret must be kept secure and should never be exposed in client-side code. Store it securely on your backend server.

Implementation Guide

The following example demonstrates how to create a React component that implements Reclaim verification with QR code functionality:

import { useState } from 'react';
import QRCode from 'react-qr-code';
import { ReclaimProofRequest } from '@reclaimprotocol/js-sdk';
 
function ReclaimDemo() {
  // State to store the verification request URL
  const [requestUrl, setRequestUrl] = useState('');
  const [proofs, setProofs] = useState([]);
 
  const getVerificationReq = async () => {
    // Your credentials from the Reclaim Developer Portal
    // Replace these with your actual credentials
    const APP_ID = 'YOUR_APPLICATION_ID';
    const APP_SECRET = 'YOUR_APPLICATION_SECRET';
    const PROVIDER_ID = 'YOUR_PROVIDER_ID';
 
    // Initialize the Reclaim SDK with your credentials
    const reclaimProofRequest = await ReclaimProofRequest.init(APP_ID, APP_SECRET, PROVIDER_ID);
 
    // Generate the verification request URL
    const requestUrl = await reclaimProofRequest.getRequestUrl();
    console.log('Request URL:', requestUrl);
    setRequestUrl(requestUrl);
 
    // Start listening for proof submissions
    await reclaimProofRequest.startSession({
      // Called when the user successfully completes the verification
      onSuccess: (proofs) => {
        if (proofs) {
          if (typeof proofs === 'string') {
            // When using a custom callback url, the proof is returned to the callback url and we get a message instead of a proof
            console.log('SDK Message:', proofs);
            setProofs([proofs]);
          } else if (typeof proofs !== 'string') {
            // When using the default callback url, we get a proof object in the response
            console.log('Verification success', proofs?.claimData.context);
            setProofs(proofs);
          }
        }
        // Add your success logic here, such as:
        // - Updating UI to show verification success
        // - Storing verification status
        // - Redirecting to another page
      },
      // Called if there's an error during verification
      onError: (error) => {
        console.error('Verification failed', error);
 
        // Add your error handling logic here, such as:
        // - Showing error message to user
        // - Resetting verification state
        // - Offering retry options
      },
    });
  };
 
  return (
    <>
      <button onClick={getVerificationReq}>Get Verification Request</button>
      {/* Display QR code when URL is available */}
      {requestUrl && (
        <div style={{ margin: '20px 0' }}>
          <QRCode value={requestUrl} />
        </div>
      )}
      {proofs && (
        <div>
          <h2>Verification Successful!</h2>
          <pre>{JSON.stringify(proofs, null, 2)}</pre>
        </div>
      )}
    </>
  );
}
 
export default ReclaimDemo;

Implementation Breakdown

1. Component Architecture

The component is structured around three main elements:

  • State management for verification URL and proofs
  • Verification request handling
  • User interface rendering

2. Verification Process Flow

a. Initialization

  • User triggers verification by clicking the button
  • SDK initializes with your credentials
  • Request URL is generated and stored in state

b. Session Management

  • Component begins monitoring for proof submissions
  • Handles both success and error scenarios
  • Supports multiple response formats (string and object)

c. User Interface

  • Displays verification button
  • Shows QR code when URL is available
  • Presents verification results

3. Response Handling

The component handles two types of proof responses:

  • String responses (when using custom callback URLs)
  • Object responses (when using default callback URL)

Integration Steps

  1. Component Integration
import ReclaimDemo from './ReclaimDemo';
 
function App() {
  return (
    <div>
      <h1>Reclaim Verification</h1>
      <ReclaimDemo />
    </div>
  );
}
  1. Environment Setup
  • Store your credentials securely
  • Configure error handling
  • Set up appropriate loading states

๐Ÿ’ก Device Detection Tip: Consider implementing device detection to optimize the user experience:

  • Desktop: Display QR code for mobile scanning
  • Mobile: Show direct verification link

๐Ÿ”’ Production Security Requirements:

  1. Never expose APP_SECRET in frontend code
  2. Generate request configurations server-side
  3. Use fromJsonString() method in frontend code
  4. Implement proper error handling and validation

Refer to the Fullstack Example for secure implementation details.

Next Steps

After implementing the basic verification:

  1. Advanced Configuration

  2. Optimization

    • Review Best Practices
    • Implement proper error handling
    • Add loading states and user feedback
  3. Testing

    • Test across different devices and browsers
    • Verify error scenarios
    • Validate security measures

Support Resources

Remember to regularly update your implementation as new SDK versions are released to ensure optimal security and performance.

On this page