refreshUser method

Future<bool> refreshUser()

Refreshes the user's authentication token and data.

This method makes an API call to refresh the user's session, updates the token, user, and hospital data, and persists them.

Returns true if the refresh is successful, false otherwise.

Implementation

Future<bool> refreshUser() async {
   _setLoading(true);
   _clearError();
   try {
     print("inside authprovider");
     final response = await _apiService.refreshUser(); // API call
     print("response = $response");
     final authResponse = AuthResponse.fromJson(response); // Parse response
     print("authresponse = $authResponse");
     await _saveAuthData(authResponse); // Save to storage
     print("Responces saved");
     return true;
   } catch (e) {
     _setError(parseApiError(e.toString()));
     return false;
   } finally {
     _setLoading(false);
   }
 }