♻️ Better http client management, no more expired token

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

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(),