33 lines
861 B
Dart
Raw Normal View History

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