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

View File

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.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 { Future<Request<T?>> requestAuthenticator<T>(Request<T?> request) async {
if (credentials != null && credentials!.isExpired) { try {
refreshCredentials(); await ensureCredentials();
}
if (credentials != null) {
request.headers['Authorization'] = 'Bearer ${credentials!.accessToken}'; request.headers['Authorization'] = 'Bearer ${credentials!.accessToken}';
} } catch (_) {}
return request; 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 { Future<void> loadCredentials() async {
if (await isAuthorized) { if (await isAuthorized) {
final content = await storage.read(key: 'auth_credentials'); final content = await storage.read(key: 'auth_credentials');
@ -124,9 +150,7 @@ class AuthProvider extends GetConnect {
return _cachedUserProfileResponse!; return _cachedUserProfileResponse!;
} }
final client = GetConnect(maxAuthRetries: 3); final client = configureClient(service: 'passport');
client.httpClient.baseUrl = ServiceFinder.services['passport'];
client.httpClient.addAuthenticator(requestAuthenticator);
final resp = await client.get('/api/users/me'); final resp = await client.get('/api/users/me');
if (resp.statusCode != 200) { if (resp.statusCode != 200) {

View File

@ -24,9 +24,7 @@ class ChatProvider extends GetxController {
} }
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized'); auth.ensureCredentials();
if (auth.credentials == null) await auth.loadCredentials();
final uri = Uri.parse( final uri = Uri.parse(
'${ServiceFinder.services['messaging']}/api/ws?tk=${auth.credentials!.accessToken}' '${ServiceFinder.services['messaging']}/api/ws?tk=${auth.credentials!.accessToken}'
@ -65,11 +63,11 @@ class ChatProvider extends GetxController {
}, },
onDone: () { onDone: () {
isConnected.value = false; isConnected.value = false;
Future.delayed(const Duration(milliseconds: 1000), () => connect()); Future.delayed(const Duration(seconds: 3), () => connect());
}, },
onError: (err) { onError: (err) {
isConnected.value = false; 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(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized'); if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect( final client = auth.configureClient(
maxAuthRetries: 3, service: 'paperclip',
timeout: const Duration(minutes: 3), timeout: const Duration(minutes: 3),
); );
client.httpClient.baseUrl = ServiceFinder.services['paperclip'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final filePayload = final filePayload =
MultipartFile(await file.readAsBytes(), filename: basename(file.path)); MultipartFile(await file.readAsBytes(), filename: basename(file.path));
@ -99,9 +97,7 @@ class AttachmentProvider extends GetConnect {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized'); if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'paperclip');
client.httpClient.baseUrl = ServiceFinder.services['paperclip'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
var resp = await client.put('/api/attachments/$id', { var resp = await client.put('/api/attachments/$id', {
'metadata': { 'metadata': {
@ -123,9 +119,7 @@ class AttachmentProvider extends GetConnect {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized'); if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'paperclip');
client.httpClient.baseUrl = ServiceFinder.services['paperclip'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
var resp = await client.delete('/api/attachments/$id'); var resp = await client.delete('/api/attachments/$id');
if (resp.statusCode != 200) { 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/models/channel.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/screens/channel/call/call.dart'; import 'package:solian/screens/channel/call/call.dart';
import 'package:solian/services.dart';
import 'package:wakelock_plus/wakelock_plus.dart'; import 'package:wakelock_plus/wakelock_plus.dart';
class ChatCallProvider extends GetxController { class ChatCallProvider extends GetxController {
@ -64,9 +63,7 @@ class ChatCallProvider extends GetxController {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized'); if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final resp = await client.post( final resp = await client.post(
'/api/channels/global/${channel.value!.alias}/calls/ongoing/token', '/api/channels/global/${channel.value!.alias}/calls/ongoing/token',

View File

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

View File

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

View File

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

View File

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

View File

@ -27,8 +27,8 @@ class _SignUpPopupState extends State<SignUpPopup> {
nickname.isEmpty || nickname.isEmpty ||
password.isEmpty) return; password.isEmpty) return;
final client = GetConnect(maxAuthRetries: 3); final client = ServiceFinder.configureClient('passport');
client.httpClient.baseUrl = ServiceFinder.services['passport'];
final resp = await client.post('/api/users', { final resp = await client.post('/api/users', {
'name': username, 'name': username,
'nick': nickname, '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/call.dart';
import 'package:solian/providers/content/channel.dart'; import 'package:solian/providers/content/channel.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/services.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/chat/call/call_prejoin.dart'; import 'package:solian/widgets/chat/call/call_prejoin.dart';
import 'package:solian/widgets/chat/call/chat_call_action.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(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return; if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final resp = await client.get( final resp = await client.get(
'/api/channels/${widget.realm}/${widget.alias}/messages?take=10&offset=$pageKey'); '/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/auth.dart';
import 'package:solian/providers/content/channel.dart'; import 'package:solian/providers/content/channel.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/services.dart';
import 'package:solian/widgets/prev_page.dart'; import 'package:solian/widgets/prev_page.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
@ -47,10 +46,6 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
final ChannelProvider provider = Get.find(); 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 scope = widget.realm != null ? widget.realm!.alias : 'global';
final payload = { final payload = {
'alias': _aliasController.value.text.toLowerCase(), '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/models/realm.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/services.dart';
import 'package:solian/widgets/account/account_avatar.dart'; import 'package:solian/widgets/account/account_avatar.dart';
import 'package:solian/widgets/attachments/attachment_publish.dart'; import 'package:solian/widgets/attachments/attachment_publish.dart';
import 'package:solian/widgets/posts/post_item.dart'; import 'package:solian/widgets/posts/post_item.dart';
@ -65,9 +64,7 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
setState(() => _isBusy = true); setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'interactive');
client.httpClient.baseUrl = ServiceFinder.services['interactive'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final payload = { final payload = {
'content': _contentController.value.text, 'content': _contentController.value.text,

View File

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

View File

@ -1,3 +1,5 @@
import 'package:get/get.dart';
abstract class ServiceFinder { abstract class ServiceFinder {
static const bool devFlag = false; static const bool devFlag = false;
@ -9,4 +11,12 @@ abstract class ServiceFinder {
devFlag ? 'http://localhost:8445' : 'https://co.solsynth.dev', devFlag ? 'http://localhost:8445' : 'https://co.solsynth.dev',
'messaging': devFlag ? 'http://localhost:8447' : 'https://im.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 { void getUserinfo() async {
setState(() => _isBusy = true); setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3); final client = GetConnect();
client.httpClient.baseUrl = ServiceFinder.services['passport']; client.httpClient.baseUrl = ServiceFinder.services['passport'];
final resp = await client.get('/api/users/${widget.account.name}'); 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/exts.dart';
import 'package:solian/models/channel.dart'; import 'package:solian/models/channel.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
class ChannelDeletionDialog extends StatefulWidget { class ChannelDeletionDialog extends StatefulWidget {
final Channel channel; final Channel channel;
@ -30,9 +29,7 @@ class _ChannelDeletionDialogState extends State<ChannelDeletionDialog> {
setState(() => _isBusy = true); setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final resp = await client final resp = await client
.delete('/api/channels/${widget.realm}/${widget.channel.id}'); .delete('/api/channels/${widget.realm}/${widget.channel.id}');
@ -51,9 +48,7 @@ class _ChannelDeletionDialogState extends State<ChannelDeletionDialog> {
setState(() => _isBusy = true); setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final resp = await client.delete( final resp = await client.delete(
'/api/channels/${widget.realm}/${widget.channel.alias}/members/me', '/api/channels/${widget.realm}/${widget.channel.alias}/members/me',

View File

@ -39,8 +39,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
void getMembers() async { void getMembers() async {
setState(() => _isBusy = true); setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3); final client = ServiceFinder.configureClient('messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
final resp = await client final resp = await client
.get('/api/channels/${widget.realm}/${widget.channel.alias}/members'); .get('/api/channels/${widget.realm}/${widget.channel.alias}/members');
@ -76,9 +75,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
setState(() => _isBusy = true); setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final resp = await client.post( final resp = await client.post(
'/api/channels/${widget.realm}/${widget.channel.alias}/members', '/api/channels/${widget.realm}/${widget.channel.alias}/members',
@ -99,9 +96,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
setState(() => _isBusy = true); setState(() => _isBusy = true);
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final resp = await client.request( final resp = await client.request(
'/api/channels/${widget.realm}/${widget.channel.alias}/members', '/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/channel.dart';
import 'package:solian/models/realm.dart'; import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
class ChatCallButton extends StatefulWidget { class ChatCallButton extends StatefulWidget {
final Realm? realm; final Realm? realm;
@ -34,9 +33,7 @@ class _ChatCallButtonState extends State<ChatCallButton> {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return; if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
setState(() => _isBusy = true); setState(() => _isBusy = true);
@ -60,9 +57,7 @@ class _ChatCallButtonState extends State<ChatCallButton> {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return; if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
setState(() => _isBusy = true); 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/message.dart';
import 'package:solian/models/realm.dart'; import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
class ChatMessageDeletionDialog extends StatefulWidget { class ChatMessageDeletionDialog extends StatefulWidget {
final Channel channel; final Channel channel;
@ -31,9 +30,7 @@ class _ChatMessageDeletionDialogState extends State<ChatMessageDeletionDialog> {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return; if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
setState(() => _isBusy = true); 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/channel.dart';
import 'package:solian/models/message.dart'; import 'package:solian/models/message.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
import 'package:solian/widgets/attachments/attachment_publish.dart'; import 'package:solian/widgets/attachments/attachment_publish.dart';
import 'package:solian/widgets/chat/chat_message.dart'; import 'package:solian/widgets/chat/chat_message.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
@ -70,9 +69,7 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
final prof = await auth.getProfile(); final prof = await auth.getProfile();
if (!await auth.isAuthorized) return; if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'messaging');
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
final payload = { final payload = {
'uuid': const Uuid().v4(), 'uuid': const Uuid().v4(),

View File

@ -29,9 +29,9 @@ class BackgroundStateWidget extends StatelessWidget {
].join('\n'), ].join('\n'),
icon: const Icon(Icons.wifi_off) icon: const Icon(Icons.wifi_off)
.animate(onPlay: (c) => c.repeat()) .animate(onPlay: (c) => c.repeat())
.fadeIn(duration: 500.ms) .fadeIn(duration: 800.ms)
.then() .then()
.fadeOut(duration: 500.ms), .fadeOut(duration: 800.ms),
onPressed: () { onPressed: () {
if (account.isConnected.isFalse) account.connect(); if (account.isConnected.isFalse) account.connect();
if (chat.isConnected.isFalse) chat.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/providers/auth.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/screens/posts/post_publish.dart'; import 'package:solian/screens/posts/post_publish.dart';
import 'package:solian/services.dart';
class PostAction extends StatefulWidget { class PostAction extends StatefulWidget {
final Post item; final Post item;
@ -154,9 +153,7 @@ class _PostDeletionDialogState extends State<PostDeletionDialog> {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return; if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'interactive');
client.httpClient.baseUrl = ServiceFinder.services['interactive'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
setState(() => _isBusy = true); setState(() => _isBusy = true);
final resp = await client.delete('/api/posts/${widget.item.id}'); 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/post.dart';
import 'package:solian/models/reaction.dart'; import 'package:solian/models/reaction.dart';
import 'package:solian/providers/auth.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_reaction.dart';
import 'package:solian/widgets/posts/post_replies.dart'; import 'package:solian/widgets/posts/post_replies.dart';
@ -51,9 +50,7 @@ class _PostQuickActionState extends State<PostQuickAction> {
if (_isSubmitting) return; if (_isSubmitting) return;
if (!await auth.isAuthorized) return; if (!await auth.isAuthorized) return;
final client = GetConnect(maxAuthRetries: 3); final client = auth.configureClient(service: 'interactive');
client.httpClient.baseUrl = ServiceFinder.services['interactive'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
setState(() => _isSubmitting = true); setState(() => _isSubmitting = true);

View File

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

View File

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