// lib/pinService.ts import * as SecureStore from 'expo-secure-store'; const PIN_KEY = 'territory_log_pin'; const PIN_ENABLED_KEY = 'territory_log_pin_enabled'; const BIOMETRIC_ENABLED_KEY = 'territory_log_biometric_enabled'; export async function isPinEnabled(): Promise { try { const val = await SecureStore.getItemAsync(PIN_ENABLED_KEY); return val === 'true'; } catch { return false; } } export async function setPin(pin: string): Promise { await SecureStore.setItemAsync(PIN_KEY, pin); await SecureStore.setItemAsync(PIN_ENABLED_KEY, 'true'); } export async function verifyPin(pin: string): Promise { try { const stored = await SecureStore.getItemAsync(PIN_KEY); return stored === pin; } catch { return false; } } export async function disablePin(): Promise { await SecureStore.deleteItemAsync(PIN_KEY); await SecureStore.setItemAsync(PIN_ENABLED_KEY, 'false'); await SecureStore.setItemAsync(BIOMETRIC_ENABLED_KEY, 'false'); } export async function getPinEnabled(): Promise { return isPinEnabled(); } export async function isBiometricEnabled(): Promise { try { const val = await SecureStore.getItemAsync(BIOMETRIC_ENABLED_KEY); return val === 'true'; } catch { return false; } } export async function setBiometricEnabled(enabled: boolean): Promise { await SecureStore.setItemAsync(BIOMETRIC_ENABLED_KEY, enabled ? 'true' : 'false'); }