store current user id
This commit is contained in:
@@ -41,6 +41,11 @@ class ApiEndpoints {
|
||||
/// Response: List of users
|
||||
static const String users = '/PortalUser/GetAllMemberUserShortInfo';
|
||||
|
||||
/// Get current logged-in user
|
||||
/// GET: /PortalUser/GetCurrentUser?getDep=false (requires auth token)
|
||||
/// Response: Current user details
|
||||
static const String getCurrentUser = '/PortalUser/GetCurrentUser?getDep=false';
|
||||
|
||||
// ==================== Warehouse Endpoints ====================
|
||||
|
||||
/// Get all warehouses
|
||||
|
||||
@@ -55,6 +55,9 @@ class SecureStorage {
|
||||
/// Key for storing email
|
||||
static const String _emailKey = 'email';
|
||||
|
||||
/// Key for storing current user ID
|
||||
static const String _currentUserIdKey = 'current_user_id';
|
||||
|
||||
// ==================== Token Management ====================
|
||||
|
||||
/// Save access token securely
|
||||
@@ -147,6 +150,25 @@ class SecureStorage {
|
||||
}
|
||||
}
|
||||
|
||||
/// Save current user ID
|
||||
Future<void> saveCurrentUserId(int userId) async {
|
||||
try {
|
||||
await _storage.write(key: _currentUserIdKey, value: userId.toString());
|
||||
} catch (e) {
|
||||
throw Exception('Failed to save current user ID: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Get current user ID
|
||||
Future<int?> getCurrentUserId() async {
|
||||
try {
|
||||
final value = await _storage.read(key: _currentUserIdKey);
|
||||
return value != null ? int.tryParse(value) : null;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to read current user ID: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if user is authenticated (has valid access token)
|
||||
Future<bool> isAuthenticated() async {
|
||||
final token = await getAccessToken();
|
||||
|
||||
Reference in New Issue
Block a user