store current user id
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../../core/di/providers.dart';
|
||||
import '../../../../core/router/app_router.dart';
|
||||
import '../../../../core/storage/secure_storage.dart';
|
||||
import '../widgets/warehouse_card.dart';
|
||||
import '../widgets/warehouse_drawer.dart';
|
||||
|
||||
@@ -28,12 +29,34 @@ class _WarehouseSelectionPageState
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Load warehouses when page is first created
|
||||
Future.microtask(() {
|
||||
Future.microtask(() async {
|
||||
ref.read(warehouseProvider.notifier).loadWarehouses();
|
||||
// Users are automatically loaded from local storage by UsersNotifier
|
||||
|
||||
// Get current user and store user ID
|
||||
await _getCurrentUserAndStoreId();
|
||||
});
|
||||
}
|
||||
|
||||
/// Get current user from API and store user ID in secure storage
|
||||
Future<void> _getCurrentUserAndStoreId() async {
|
||||
try {
|
||||
final secureStorage = SecureStorage();
|
||||
final usersDataSource = ref.read(usersRemoteDataSourceProvider);
|
||||
|
||||
// Call API to get current user
|
||||
final currentUser = await usersDataSource.getCurrentUser();
|
||||
|
||||
// Store the current user ID
|
||||
await secureStorage.saveCurrentUserId(currentUser.id);
|
||||
|
||||
debugPrint('Current user ID stored: ${currentUser.id}');
|
||||
} catch (e) {
|
||||
// Silently fail - this is not critical
|
||||
debugPrint('Error getting current user: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Watch warehouse state
|
||||
|
||||
Reference in New Issue
Block a user