♻️ Refactored auth system

This commit is contained in:
2024-07-25 01:18:47 +08:00
parent ef58430060
commit 6d92a16a62
38 changed files with 444 additions and 523 deletions

View File

@ -86,7 +86,7 @@ class AttachmentProvider extends GetConnect {
Map<String, dynamic>? metadata,
) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient(
'files',
@ -130,7 +130,7 @@ class AttachmentProvider extends GetConnect {
bool isMature = false,
}) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('files');
@ -152,7 +152,7 @@ class AttachmentProvider extends GetConnect {
Future<Response> deleteAttachment(int id) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('files');

View File

@ -16,7 +16,7 @@ class ChannelProvider extends GetxController {
Future<void> refreshAvailableChannel() async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
isLoading.value = true;
final resp = await listAvailableChannel();
@ -29,7 +29,7 @@ class ChannelProvider extends GetxController {
Future<Response> getChannel(String alias, {String realm = 'global'}) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('messaging');
@ -44,7 +44,7 @@ class ChannelProvider extends GetxController {
Future<Response> getMyChannelProfile(String alias,
{String realm = 'global'}) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('messaging');
@ -59,7 +59,7 @@ class ChannelProvider extends GetxController {
Future<Response?> getChannelOngoingCall(String alias,
{String realm = 'global'}) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('messaging');
@ -75,7 +75,7 @@ class ChannelProvider extends GetxController {
Future<Response> listChannel({String scope = 'global'}) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('messaging');
@ -89,7 +89,7 @@ class ChannelProvider extends GetxController {
Future<Response> listAvailableChannel({String realm = 'global'}) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('messaging');
@ -103,7 +103,7 @@ class ChannelProvider extends GetxController {
Future<Response> createChannel(String scope, dynamic payload) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('messaging');
@ -118,7 +118,7 @@ class ChannelProvider extends GetxController {
Future<Response?> createDirectChannel(
BuildContext context, String scope) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final related = await showModalBottomSheet(
useRootNavigator: true,
@ -129,14 +129,14 @@ class ChannelProvider extends GetxController {
);
if (related == null) return null;
final prof = await auth.getProfile();
final prof = auth.userProfile.value!;
final client = auth.configureClient('messaging');
final resp = await client.post('/channels/$scope/dm', {
'alias': const Uuid().v4().replaceAll('-', '').substring(0, 12),
'name': 'DM',
'description':
'A direct message channel between @${prof.body['name']} and @${related.name}',
'A direct message channel between @${prof['name']} and @${related.name}',
'related_user': related.id,
'is_encrypted': false,
});
@ -149,7 +149,7 @@ class ChannelProvider extends GetxController {
Future<Response> updateChannel(String scope, int id, dynamic payload) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('messaging');

View File

@ -27,7 +27,7 @@ class PostProvider extends GetConnect {
Future<Response> listDraft(int page) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final queries = [
'take=${10}',

View File

@ -4,7 +4,7 @@ import 'package:solian/providers/auth.dart';
class RealmProvider extends GetxController {
Future<Response> getRealm(String alias) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('auth');
@ -18,7 +18,7 @@ class RealmProvider extends GetxController {
Future<Response> listAvailableRealm() async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
final client = auth.configureClient('auth');