5️⃣ Backup

Back up your user's data so you can restore their Keyless account when necessary.

Create backups after authentication, and push them into your backup system. Each backup is encrypted with aes-gcm using the backupKey as symmetric key. You need both backupData and backupKey to restore an account with Keyless.

import 'package:keyless_flutter_sdk/keyless.dart';
import 'package:keyless_flutter_sdk/models/configurations/authentication_configuration.dart';

// Retrieve temporary state during authentication
final configuration = BiomAuthConfig(shouldRetrieveTemporaryState: true);

try {
    final result = await Keyless.instance.authenticate(configuration);
    if (result.temporaryState != null) {
        print("Temporary state retrieved successfully");
        // Store temporaryState securely
    }
} catch (error) {
    print("Failed to retrieve temporary state: $error");
}

Restore the user account by providing backupData and backupKey to the withBackup method:

import 'package:keyless_flutter_sdk/keyless.dart';
import 'package:keyless_flutter_sdk/models/configurations/enrollment_configuration.dart';

// Create enrollment configuration with backup
final configuration = BiomEnrollConfig(
    backup: KeylessBackup(
        data: backupData,
        key: backupKey
    )
);

try {
    final result = await Keyless.instance.enroll(configuration);
    print("Enrollment from backup successful");
} catch (error) {
    print("Enrollment from backup failed: $error");
}

Last updated

Was this helpful?