33 lines
875 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();
if (!await auth.isAuthorized) throw Exception('unauthorized');
2024-06-22 22:39:32 +08:00
final client = auth.configureClient('passport');
2024-05-29 22:42:11 +08:00
final resp = await client.get('/api/realms/$alias');
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();
if (!await auth.isAuthorized) throw Exception('unauthorized');
2024-06-22 22:39:32 +08:00
final client = auth.configureClient('passport');
2024-05-26 00:11:00 +08:00
2024-05-28 22:13:23 +08:00
final resp = await client.get('/api/realms/me/available');
2024-05-26 00:11:00 +08:00
if (resp.statusCode != 200) {
throw Exception(resp.bodyString);
}
return resp;
}
}