♻️ Better http client management, no more expired token

This commit is contained in:
LittleSheep 2024-06-06 20:49:18 +08:00
parent d1a8793550
commit ce15944018
26 changed files with 96 additions and 152 deletions

View File

@ -43,7 +43,7 @@ class AccountProvider extends GetxController {
}
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
auth.ensureCredentials();
if (auth.credentials == null) await auth.loadCredentials();
@ -91,11 +91,11 @@ class AccountProvider extends GetxController {
},
onDone: () {
isConnected.value = false;
Future.delayed(const Duration(milliseconds: 1000), () => connect());
Future.delayed(const Duration(seconds: 3), () => connect());
},
onError: (err) {
isConnected.value = false;
Future.delayed(const Duration(milliseconds: 1000), () => connect());
Future.delayed(const Duration(seconds: 3), () => connect());
},
);
}
@ -153,9 +153,7 @@ class AccountProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
final resp = await client.get('/api/notifications?skip=0&take=100');
if (resp.statusCode == 200) {

View File

@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
@ -49,17 +50,42 @@ class AuthProvider extends GetConnect {
}
Future<Request<T?>> requestAuthenticator<T>(Request<T?> request) async {
if (credentials != null && credentials!.isExpired) {
refreshCredentials();
}
if (credentials != null) {
try {
await ensureCredentials();
request.headers['Authorization'] = 'Bearer ${credentials!.accessToken}';
}
} catch (_) {}
return request;
}
GetConnect configureClient({
String? service,
timeout = const Duration(seconds: 5),
}) {
final client = GetConnect(
maxAuthRetries: 3,
timeout: timeout,
allowAutoSignedCert: true,
);
client.httpClient.addAuthenticator(requestAuthenticator);
if (service != null) {
client.httpClient.baseUrl = ServiceFinder.services[service];
}
return client;
}
Future<void> ensureCredentials() async {
if (!await isAuthorized) throw Exception('unauthorized');
if (credentials == null) await loadCredentials();
if (credentials!.isExpired) {
await refreshCredentials();
log("Refreshed credentials at ${DateTime.now()}");
}
}
Future<void> loadCredentials() async {
if (await isAuthorized) {
final content = await storage.read(key: 'auth_credentials');
@ -124,9 +150,7 @@ class AuthProvider extends GetConnect {
return _cachedUserProfileResponse!;
}
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(requestAuthenticator);
final client = configureClient(service: 'passport');
final resp = await client.get('/api/users/me');
if (resp.statusCode != 200) {

View File

@ -24,9 +24,7 @@ class ChatProvider extends GetxController {
}
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
if (auth.credentials == null) await auth.loadCredentials();
auth.ensureCredentials();
final uri = Uri.parse(
'${ServiceFinder.services['messaging']}/api/ws?tk=${auth.credentials!.accessToken}'
@ -65,11 +63,11 @@ class ChatProvider extends GetxController {
},
onDone: () {
isConnected.value = false;
Future.delayed(const Duration(milliseconds: 1000), () => connect());
Future.delayed(const Duration(seconds: 3), () => connect());
},
onError: (err) {
isConnected.value = false;
Future.delayed(const Duration(milliseconds: 1000), () => connect());
Future.delayed(const Duration(seconds: 3), () => connect());
},
);
}

View File

@ -50,12 +50,10 @@ class AttachmentProvider extends GetConnect {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(
maxAuthRetries: 3,
final client = auth.configureClient(
service: 'paperclip',
timeout: const Duration(minutes: 3),
);
client.httpClient.baseUrl = ServiceFinder.services['paperclip'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final filePayload =
MultipartFile(await file.readAsBytes(), filename: basename(file.path));
@ -99,9 +97,7 @@ class AttachmentProvider extends GetConnect {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['paperclip'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'paperclip');
var resp = await client.put('/api/attachments/$id', {
'metadata': {
@ -123,9 +119,7 @@ class AttachmentProvider extends GetConnect {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['paperclip'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'paperclip');
var resp = await client.delete('/api/attachments/$id');
if (resp.statusCode != 200) {

View File

@ -9,7 +9,6 @@ import 'package:solian/models/call.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/screens/channel/call/call.dart';
import 'package:solian/services.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
class ChatCallProvider extends GetxController {
@ -64,9 +63,7 @@ class ChatCallProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client.post(
'/api/channels/global/${channel.value!.alias}/calls/ongoing/token',

View File

@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
import 'package:solian/widgets/account/friend_select.dart';
import 'package:uuid/uuid.dart';
@ -10,8 +9,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
final client = auth.configureClient(service: 'messaging');
final resp = await client.get('/api/channels/$realm/$alias');
if (resp.statusCode != 200) {
@ -26,8 +24,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
final client = auth.configureClient(service: 'messaging');
final resp = await client.get('/api/channels/$realm/$alias/calls/ongoing');
if (resp.statusCode == 404) {
@ -43,9 +40,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client.get('/api/channels/$scope');
if (resp.statusCode != 200) {
@ -59,9 +54,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client.get('/api/channels/$realm/me/available');
if (resp.statusCode != 200) {
@ -75,9 +68,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client.post('/api/channels/$scope', payload);
if (resp.statusCode != 200) {
@ -102,9 +93,7 @@ class ChannelProvider extends GetxController {
if (related == null) return null;
final prof = await auth.getProfile();
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client.post('/api/channels/$scope/dm', {
'alias': const Uuid().v4().replaceAll('-', '').substring(0, 12),
@ -125,9 +114,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client.put('/api/channels/$scope/$id', payload);
if (resp.statusCode != 200) {

View File

@ -1,14 +1,12 @@
import 'package:get/get.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
class RealmProvider extends GetxController {
Future<Response> getRealm(String alias) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
final client = auth.configureClient(service: 'passport');
final resp = await client.get('/api/realms/$alias');
if (resp.statusCode != 200) {
@ -22,9 +20,7 @@ class RealmProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
final resp = await client.get('/api/realms/me/available');
if (resp.statusCode != 200) {

View File

@ -3,7 +3,6 @@ import 'package:flutter_animate/flutter_animate.dart';
import 'package:get/get.dart';
import 'package:solian/providers/account.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
import 'package:solian/models/notification.dart' as notify;
import 'package:url_launcher/url_launcher_string.dart';
import 'package:uuid/uuid.dart';
@ -33,9 +32,7 @@ class _NotificationScreenState extends State<NotificationScreen> {
}
if (markList.isNotEmpty) {
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
await client.put('/api/notifications/batch/read', {'messages': markList});
}
@ -58,9 +55,7 @@ class _NotificationScreenState extends State<NotificationScreen> {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
await client.put('/api/notifications/${element.id}/read', {});

View File

@ -98,9 +98,7 @@ class _PersonalizeScreenState extends State<PersonalizeScreen> {
context.showErrorDialog(e);
}
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
final resp = await client.put(
'/api/users/me/$position',
@ -122,9 +120,7 @@ class _PersonalizeScreenState extends State<PersonalizeScreen> {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
_birthday?.toIso8601String();
final resp = await client.put(

View File

@ -27,8 +27,8 @@ class _SignUpPopupState extends State<SignUpPopup> {
nickname.isEmpty ||
password.isEmpty) return;
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
final client = ServiceFinder.configureClient('passport');
final resp = await client.post('/api/users', {
'name': username,
'nick': nickname,

View File

@ -15,7 +15,6 @@ import 'package:solian/providers/chat.dart';
import 'package:solian/providers/content/call.dart';
import 'package:solian/providers/content/channel.dart';
import 'package:solian/router.dart';
import 'package:solian/services.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/chat/call/call_prejoin.dart';
import 'package:solian/widgets/chat/call/chat_call_action.dart';
@ -103,9 +102,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client.get(
'/api/channels/${widget.realm}/${widget.alias}/messages?take=10&offset=$pageKey');

View File

@ -7,7 +7,6 @@ import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/providers/content/channel.dart';
import 'package:solian/router.dart';
import 'package:solian/services.dart';
import 'package:solian/widgets/prev_page.dart';
import 'package:uuid/uuid.dart';
@ -47,10 +46,6 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
final ChannelProvider provider = Get.find();
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final scope = widget.realm != null ? widget.realm!.alias : 'global';
final payload = {
'alias': _aliasController.value.text.toLowerCase(),

View File

@ -7,7 +7,6 @@ import 'package:solian/models/post.dart';
import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
import 'package:solian/services.dart';
import 'package:solian/widgets/account/account_avatar.dart';
import 'package:solian/widgets/attachments/attachment_publish.dart';
import 'package:solian/widgets/posts/post_item.dart';
@ -65,9 +64,7 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['interactive'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'interactive');
final payload = {
'content': _contentController.value.text,

View File

@ -5,7 +5,6 @@ import 'package:solian/exts.dart';
import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
import 'package:solian/services.dart';
import 'package:solian/widgets/prev_page.dart';
import 'package:uuid/uuid.dart';
@ -42,9 +41,7 @@ class _RealmOrganizeScreenState extends State<RealmOrganizeScreen> {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
final payload = {
'alias': _aliasController.value.text.toLowerCase(),

View File

@ -1,3 +1,5 @@
import 'package:get/get.dart';
abstract class ServiceFinder {
static const bool devFlag = false;
@ -9,4 +11,12 @@ abstract class ServiceFinder {
devFlag ? 'http://localhost:8445' : 'https://co.solsynth.dev',
'messaging': devFlag ? 'http://localhost:8447' : 'https://im.solsynth.dev',
};
static GetConnect configureClient(String service,
{timeout = const Duration(seconds: 5)}) {
final client = GetConnect(timeout: timeout, allowAutoSignedCert: true);
client.httpClient.baseUrl = ServiceFinder.services[service];
return client;
}
}

View File

@ -22,7 +22,7 @@ class _AccountProfilePopupState extends State<AccountProfilePopup> {
void getUserinfo() async {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
final client = GetConnect();
client.httpClient.baseUrl = ServiceFinder.services['passport'];
final resp = await client.get('/api/users/${widget.account.name}');

View File

@ -3,7 +3,6 @@ import 'package:get/get.dart';
import 'package:solian/exts.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
class ChannelDeletionDialog extends StatefulWidget {
final Channel channel;
@ -30,9 +29,7 @@ class _ChannelDeletionDialogState extends State<ChannelDeletionDialog> {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client
.delete('/api/channels/${widget.realm}/${widget.channel.id}');
@ -51,9 +48,7 @@ class _ChannelDeletionDialogState extends State<ChannelDeletionDialog> {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client.delete(
'/api/channels/${widget.realm}/${widget.channel.alias}/members/me',

View File

@ -39,8 +39,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
void getMembers() async {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
final client = ServiceFinder.configureClient('messaging');
final resp = await client
.get('/api/channels/${widget.realm}/${widget.channel.alias}/members');
@ -76,9 +75,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client.post(
'/api/channels/${widget.realm}/${widget.channel.alias}/members',
@ -99,9 +96,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final resp = await client.request(
'/api/channels/${widget.realm}/${widget.channel.alias}/members',

View File

@ -5,7 +5,6 @@ import 'package:solian/models/call.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
class ChatCallButton extends StatefulWidget {
final Realm? realm;
@ -34,9 +33,7 @@ class _ChatCallButtonState extends State<ChatCallButton> {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
setState(() => _isBusy = true);
@ -60,9 +57,7 @@ class _ChatCallButtonState extends State<ChatCallButton> {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
setState(() => _isBusy = true);

View File

@ -5,7 +5,6 @@ import 'package:solian/models/channel.dart';
import 'package:solian/models/message.dart';
import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
class ChatMessageDeletionDialog extends StatefulWidget {
final Channel channel;
@ -31,9 +30,7 @@ class _ChatMessageDeletionDialogState extends State<ChatMessageDeletionDialog> {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
setState(() => _isBusy = true);

View File

@ -6,7 +6,6 @@ import 'package:solian/models/account.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/models/message.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
import 'package:solian/widgets/attachments/attachment_publish.dart';
import 'package:solian/widgets/chat/chat_message.dart';
import 'package:uuid/uuid.dart';
@ -70,9 +69,7 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
final prof = await auth.getProfile();
if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'messaging');
final payload = {
'uuid': const Uuid().v4(),

View File

@ -29,9 +29,9 @@ class BackgroundStateWidget extends StatelessWidget {
].join('\n'),
icon: const Icon(Icons.wifi_off)
.animate(onPlay: (c) => c.repeat())
.fadeIn(duration: 500.ms)
.fadeIn(duration: 800.ms)
.then()
.fadeOut(duration: 500.ms),
.fadeOut(duration: 800.ms),
onPressed: () {
if (account.isConnected.isFalse) account.connect();
if (chat.isConnected.isFalse) chat.connect();

View File

@ -9,7 +9,6 @@ import 'package:solian/models/post.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/posts/post_publish.dart';
import 'package:solian/services.dart';
class PostAction extends StatefulWidget {
final Post item;
@ -154,9 +153,7 @@ class _PostDeletionDialogState extends State<PostDeletionDialog> {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['interactive'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'interactive');
setState(() => _isBusy = true);
final resp = await client.delete('/api/posts/${widget.item.id}');

View File

@ -4,7 +4,6 @@ import 'package:solian/exts.dart';
import 'package:solian/models/post.dart';
import 'package:solian/models/reaction.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
import 'package:solian/widgets/posts/post_reaction.dart';
import 'package:solian/widgets/posts/post_replies.dart';
@ -51,9 +50,7 @@ class _PostQuickActionState extends State<PostQuickAction> {
if (_isSubmitting) return;
if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['interactive'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'interactive');
setState(() => _isSubmitting = true);

View File

@ -3,7 +3,6 @@ import 'package:get/get.dart';
import 'package:solian/exts.dart';
import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
class RealmDeletionDialog extends StatefulWidget {
final Realm realm;
@ -22,15 +21,13 @@ class RealmDeletionDialog extends StatefulWidget {
class _RealmDeletionDialogState extends State<RealmDeletionDialog> {
bool _isBusy = false;
Future<void> deleteChannel() async {
Future<void> deleteRealm() async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
final resp = await client.delete('/api/realms/${widget.realm.id}');
if (resp.statusCode != 200) {
@ -42,15 +39,13 @@ class _RealmDeletionDialogState extends State<RealmDeletionDialog> {
setState(() => _isBusy = false);
}
Future<void> leaveChannel() async {
Future<void> leaveRealm() async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
final resp =
await client.delete('/api/realms/${widget.realm.id}/members/me');
@ -80,8 +75,8 @@ class _RealmDeletionDialogState extends State<RealmDeletionDialog> {
onPressed: _isBusy
? null
: widget.isOwned
? deleteChannel
: leaveChannel,
? deleteRealm
: leaveRealm,
child: Text('confirm'.tr),
),
],

View File

@ -37,8 +37,7 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
void getMembers() async {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
final client = ServiceFinder.configureClient('passport');
final resp = await client.get('/api/realms/${widget.realm.alias}/members');
if (resp.statusCode == 200) {
@ -73,9 +72,7 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
final resp = await client.post(
'/api/realms/${widget.realm.alias}/members',
@ -96,9 +93,7 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final client = auth.configureClient(service: 'passport');
final resp = await client.request(
'/api/realms/${widget.realm.alias}/members',