- The profile and the access token are hidden.
- Every protected call and every refresh fails with a “session locked” error.
- On unlock, the SDK restores the session from the secure store, without a network call.
Requirements
The Flutter SDK does not have the idle lock yet.
How it works
- Create the lock with a threshold, the number of seconds the app can stay in the background before it locks, and start it.
- Set a passcode after sign-in. The lock does nothing until a passcode is set, so there is always a way back in. Show a “set a passcode” screen while no passcode is set.
- Optionally enable biometrics as a shortcut past the passcode.
- The app goes to the background. When it comes back after more than the threshold, the SDK seals the client and reports the lock as locked. Show your lock screen.
- The user unlocks with the passcode or with biometrics. The SDK unseals the client and the session continues.
- On sign-out, disable the lock. This forgets the passcode and the biometric shortcut.
lockOnStart), so closing and reopening the app is not a way past it.
Wrong passcodes are limited to maxAttempts (default 5). After the last one, unlocking with the passcode fails with a “locked out” error: sign the user out.
The passcode never leaves the device. On a device, the SDK protects it with the Keychain (iOS) or a key in the Android Keystore, and the biometric shortcut is an item that the system only releases after a successful biometric check.
Platform setup
- iOS
- Android
- React Native
For biometrics, add
NSFaceIDUsageDescription to your app’s Info.plist. iOS shows this text the first time the app uses Face ID:Create and start the lock
Create one lock per client, start it once, and keep it for the life of the client.- iOS
- Android
- React Native
PreludeIdleLock is an ObservableObject. Its published properties drive your screens:Other parameters:
lockOnStart (default true) and maxAttempts (default 5).Set the passcode
Ask for a passcode right after sign-in, whileisEnabled is false. The passcode needs at least 4 characters. Setting a new passcode replaces the old one and turns biometrics off, so the user enables it again.
- iOS
- Android
- React Native
Enable biometrics
Offer biometrics whenisBiometricsAvailable is true. It needs a passcode first.
- iOS
- Android
- React Native
Unlock
Show your lock screen whileisLocked is true. The SDK does not show a biometric prompt on its own: call unlockWithBiometrics from a button, or when the lock screen appears.
- iOS
- Android
- React Native
lock(). It does nothing when no passcode is set.
Sign out
On sign-out, calldisable(). It forgets the passcode and the biometric shortcut and removes the lock, so the next user of the device starts without them. With the React layer, signOut() does this for you.
React hooks
WithPreludeAuthProvider, pass the lock options as the idleLock prop. The provider creates and starts the lock before it restores the session, so with lockOnStart a relaunch lands on the lock screen.
- While the session is locked,
useAuth().stageis"locked"anduserisnull, soSignedInunmounts andLockedrenders. - In
Home, show a passcode setup whileuseIdleLock().isEnabledisfalse. - Hook actions never throw: a wrong passcode lands in
useIdleLock().error. OnLockedOutErrorthe provider signs the user out. - Every path that ends the session (
signOut, a rejected refresh, a launch with no session) forgets the passcode.
Errors
Each SDK names these errors in its own convention, for example
PreludeAuthError.lockedOut (iOS), PreludeAuthError.LockedOut (Android), and LockedOutError (React Native).
Test on a simulator or emulator
- iOS Simulator: setting a passcode needs
PreludeAuth0.8.1 or later (React Native 0.8.1 or later). For biometrics, turn on Features > Face ID > Enrolled. The simulator does not show the Face ID sheet for the biometric unlock, so test the face check itself on a device. - Android emulator: set a screen lock and enroll a fingerprint in Settings > Security, then touch the sensor from the emulator’s extended controls (Fingerprint), or with
adb -e emu finger touch 1.