Revamp Done - Support for Individual and Jwellery module added
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:local_auth/local_auth.dart';
|
||||
import 'core/theme/app_theme.dart';
|
||||
import 'core/theme/theme_provider.dart';
|
||||
import 'features/auth/presentation/auth_screen.dart';
|
||||
import 'features/auth/presentation/setup_wizard_screen.dart';
|
||||
import 'features/dashboard/presentation/dashboard_screen.dart';
|
||||
import 'features/onboarding/presentation/onboarding_screen.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -31,6 +32,7 @@ class KifiApp extends ConsumerStatefulWidget {
|
||||
class _KifiAppState extends ConsumerState<KifiApp> {
|
||||
bool _isLoading = true;
|
||||
bool _isAuthenticated = false;
|
||||
bool _isSetupCompleted = true;
|
||||
bool _hasSeenOnboarding = false;
|
||||
final LocalAuthentication _localAuth = LocalAuthentication();
|
||||
String? _startupError;
|
||||
@@ -43,11 +45,11 @@ class _KifiAppState extends ConsumerState<KifiApp> {
|
||||
|
||||
Future<bool> _authenticateWithBiometrics() async {
|
||||
try {
|
||||
final canCheckBiometrics = await _localAuth.canCheckBiometrics;
|
||||
final isAvailable = await _localAuth.canCheckBiometrics;
|
||||
final isDeviceSupported = await _localAuth.isDeviceSupported();
|
||||
|
||||
if (!canCheckBiometrics && !isDeviceSupported) {
|
||||
return true; // Pass if device doesn't support biometrics to avoid locking users out
|
||||
if (!isAvailable || !isDeviceSupported) {
|
||||
return true; // If device does not support biometrics, allow access via stored token
|
||||
}
|
||||
|
||||
return await _localAuth.authenticate(
|
||||
@@ -79,11 +81,27 @@ class _KifiAppState extends ConsumerState<KifiApp> {
|
||||
return; // User failed biometrics, leave them on login screen
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isAuthenticated = true;
|
||||
_hasSeenOnboarding = hasSeenOnboarding;
|
||||
_isLoading = false;
|
||||
});
|
||||
// Validate token and check account setup status with backend
|
||||
try {
|
||||
final res = await DioClient().dio.get('/account/setup/status');
|
||||
final status = res.data != null ? res.data['status'] : null;
|
||||
|
||||
setState(() {
|
||||
_isAuthenticated = true;
|
||||
_isSetupCompleted = status == 'COMPLETED';
|
||||
_hasSeenOnboarding = hasSeenOnboarding;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (_) {
|
||||
// Token is stale / invalid / user was wiped from DB -> clear token and go to AuthScreen
|
||||
await storage.delete(key: 'jwt_token');
|
||||
await DioClient().clearToken();
|
||||
setState(() {
|
||||
_isAuthenticated = false;
|
||||
_hasSeenOnboarding = hasSeenOnboarding;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
setState(() {
|
||||
_isAuthenticated = false;
|
||||
@@ -91,7 +109,7 @@ class _KifiAppState extends ConsumerState<KifiApp> {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
} catch (e, stacktrace) {
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_startupError = e.toString();
|
||||
_isLoading = false;
|
||||
@@ -116,7 +134,9 @@ class _KifiAppState extends ConsumerState<KifiApp> {
|
||||
? const Scaffold(body: Center(child: CircularProgressIndicator()))
|
||||
: (!_hasSeenOnboarding
|
||||
? const OnboardingScreen()
|
||||
: (_isAuthenticated ? const DashboardScreen() : const AuthScreen())),
|
||||
: (_isAuthenticated
|
||||
? (_isSetupCompleted ? const DashboardScreen() : const SetupWizardScreen())
|
||||
: const AuthScreen())),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user