Skip to main content

On Credential Accepted Event

Fires when the SDK has successfully added one or more credentials to the user’s wallet after a credential offer flow.

  • Purpose: Let your application know new credentials are available so you can persist them, update UI lists, and trigger any follow-up logic (e.g. issuing notifications or unlocking features).

  • Functionality: The handler receives an array of Credential objects containing:

    • schemaId (string) – Identifier of the credential schema.
    • attributes (object) – Key/value pairs of the credential data, including a _namespace field indicating the credential type.
    • Other metadata such as issuerDid, issuedAt, and raw credentialId.
  • Usage:

    1. Persist the credentials in secure storage (SQLite, AsyncStorage).
    2. Emit app-specific events to update credential lists or badges.
    3. Branch logic based on credential type (e.g., identity card vs biometric) to launch additional workflows.
    4. Notify the user that a new credential has been added (toast, modal, or push notification).
  • Example:

    import { Credential } from '@one37id/mobile-js-sdk';
    import { eventEmitter, credentialEventEmitter } from '../services';
    import AsyncStorage from '@react-native-async-storage/async-storage';

    const handlers: EventHandlers = {
    onCredentialAccepted: async (credentials: Credential[]) => {
    console.log('Credential accepted:', credentials[0].schemaId);

    try {
    // 1) Emit a generic 'issued' event
    credentialEventEmitter.emitCredentialIssued(credentials);

    // 2) Branch by namespace
    const namespaceList = credentials.map(c => c.attributes._namespace);
    if (namespaceList.includes('personal.contact.verifiedphone')) {
    eventEmitter.emit('phoneNumberCredentialVerified', true);
    }
    if (namespaceList.includes('personal.biographic.identitycard')) {
    await AsyncStorage.setItem('hasIdentityCredential', 'true');
    eventEmitter.emit('CredentialsAcquired');
    }
    if (namespaceList.includes('personal.biometric.voice')) {
    eventEmitter.emit('VoiceCredentialAcquired');
    }

    // 3) Persist credentials securely
    await credentialStorage.saveMany(credentials);

    } catch (error) {
    console.error('Error in onCredentialAccepted:', error);
    }
    },
    };

X

Graph View