fix secure storage and release pipeline
All checks were successful
All checks were successful
This commit is contained in:
@@ -107,7 +107,7 @@ jobs:
|
|||||||
SUDO=""
|
SUDO=""
|
||||||
fi
|
fi
|
||||||
$SUDO apt-get update
|
$SUDO apt-get update
|
||||||
$SUDO apt-get install -y unzip xz-utils zip libstdc++6 libglu1-mesa clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev curl jq
|
$SUDO apt-get install -y unzip xz-utils zip libstdc++6 libglu1-mesa clang cmake ninja-build pkg-config libgtk-3-dev libsecret-1-dev liblzma-dev curl jq
|
||||||
|
|
||||||
- name: Setup Flutter
|
- name: Setup Flutter
|
||||||
uses: subosito/flutter-action@v2
|
uses: subosito/flutter-action@v2
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ void main() {
|
|||||||
ProxyProvider<AuthService, void>(
|
ProxyProvider<AuthService, void>(
|
||||||
update: (_, auth, __) {
|
update: (_, auth, __) {
|
||||||
api.setTokenProvider(() => auth.token);
|
api.setTokenProvider(() => auth.token);
|
||||||
|
api.setUnauthorizedHandler(() => auth.handleTokenExpired());
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ChangeNotifierProxyProvider<ApiService, DataService>(
|
ChangeNotifierProxyProvider<ApiService, DataService>(
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ import 'dart:convert';
|
|||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
typedef TokenProvider = String? Function();
|
typedef TokenProvider = String? Function();
|
||||||
|
typedef UnauthorizedHandler = Future<void> Function();
|
||||||
|
|
||||||
class ApiService {
|
class ApiService {
|
||||||
final String baseUrl;
|
final String baseUrl;
|
||||||
TokenProvider? _getToken;
|
TokenProvider? _getToken;
|
||||||
|
UnauthorizedHandler? _onUnauthorized;
|
||||||
|
|
||||||
ApiService({required this.baseUrl});
|
ApiService({required this.baseUrl});
|
||||||
|
|
||||||
@@ -13,6 +15,10 @@ class ApiService {
|
|||||||
_getToken = provider;
|
_getToken = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setUnauthorizedHandler(UnauthorizedHandler handler) {
|
||||||
|
_onUnauthorized = handler;
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, String> _buildHeaders(Map<String, String>? extra) {
|
Map<String, String> _buildHeaders(Map<String, String>? extra) {
|
||||||
final token = _getToken?.call();
|
final token = _getToken?.call();
|
||||||
final headers = {'accept': 'application/json', ...?extra};
|
final headers = {'accept': 'application/json', ...?extra};
|
||||||
@@ -85,12 +91,19 @@ class ApiService {
|
|||||||
return {'Content-Type': 'application/json', if (extra != null) ...extra};
|
return {'Content-Type': 'application/json', if (extra != null) ...extra};
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic _processResponse(http.Response res) {
|
Future<dynamic> _processResponse(http.Response res) async {
|
||||||
final body = res.body.isNotEmpty ? jsonDecode(res.body) : null;
|
final body = res.body.isNotEmpty ? jsonDecode(res.body) : null;
|
||||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||||
return body;
|
return body;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (res.statusCode == 401 &&
|
||||||
|
body is Map<String, dynamic> &&
|
||||||
|
body['detail'] == 'Not authenticated' &&
|
||||||
|
_onUnauthorized != null) {
|
||||||
|
await _onUnauthorized!();
|
||||||
|
}
|
||||||
|
|
||||||
throw Exception('API error ${res.statusCode}: $body');
|
throw Exception('API error ${res.statusCode}: $body');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user