♻️ Better http client management, no more expired token
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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',
|
||||
|
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user