Skip to content

Commit

Permalink
Fix switching environment issue (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ida631 authored Nov 16, 2024
1 parent db86b18 commit 56d9bbb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions data/lib/repositories/api_env_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class APIEnvironmentRepositoryImpl implements APIEnvironmentRepository {
final prefs = await SharedPreferences.getInstance();
final String currentEnvironment = prefs.getString(_environmentKey) ?? "production";
if (currentEnvironment == "production") {
return "http://localhost:8080/api";
} else {
return "http://compositesai.eba-dxj2wppi.us-west-2.elasticbeanstalk.com/api";
} else {
return "http://localhost:8080/api";
}
}
}
6 changes: 5 additions & 1 deletion domain/lib/usecases/auth_usecase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ class AuthUseCase {
}

Future<void> logout() async {
final accessToken = await tokenProvider.getToken();
if (accessToken == null || accessToken == "") {
return;
}
try {
await repository.logout();
} catch (e) {
rethrow;
} finally {
tokenProvider.deleteToken();
await tokenProvider.deleteToken();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class QASettingsViewModel extends ChangeNotifier {
await authUseCase.logout();
} catch (e) {
print('Error during logout: $e');
} finally {
await apiEnvironmentUseCase.changeAPIEnvironment(environment);
currentEnvironment = environment;
isLoading = false;
notifyListeners();
}
await apiEnvironmentUseCase.changeAPIEnvironment(environment);
currentEnvironment = environment;
isLoading = false;
notifyListeners();
}
}

0 comments on commit 56d9bbb

Please sign in to comment.