Solian/lib/providers/content/realm.dart

33 lines
861 B
Dart
Raw Normal View History

2024-05-25 16:11:00 +00:00
import 'package:get/get.dart';
import 'package:solian/providers/auth.dart';
class RealmProvider extends GetxController {
2024-05-29 14:42:11 +00:00
Future<Response> getRealm(String alias) async {
final AuthProvider auth = Get.find();
2024-07-24 17:18:47 +00:00
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
2024-05-29 14:42:11 +00:00
final client = auth.configureClient('auth');
2024-05-29 14:42:11 +00:00
final resp = await client.get('/realms/$alias');
2024-05-29 14:42:11 +00:00
if (resp.statusCode != 200) {
throw Exception(resp.bodyString);
}
return resp;
}
2024-05-25 16:11:00 +00:00
Future<Response> listAvailableRealm() async {
final AuthProvider auth = Get.find();
2024-07-24 17:18:47 +00:00
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
2024-05-25 16:11:00 +00:00
final client = auth.configureClient('auth');
2024-05-25 16:11:00 +00:00
final resp = await client.get('/realms/me/available');
2024-05-25 16:11:00 +00:00
if (resp.statusCode != 200) {
throw Exception(resp.bodyString);
}
return resp;
}
}