feat: split legacy/payment apps via APP_MODE flag
This commit is contained in:
@@ -29,11 +29,11 @@ Future<void> configureDependencies(
|
||||
cookieJar: cookieJar,
|
||||
);
|
||||
|
||||
if (onTokenExpired != null && onUnauthorized != null) {
|
||||
if (onUnauthorized != null) {
|
||||
dio.interceptors.add(
|
||||
TreezorTokenInterceptor(
|
||||
onTokenExpired: onTokenExpired,
|
||||
onUnauthorized: onUnauthorized,
|
||||
onTokenExpired: onTokenExpired,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,32 +4,53 @@ import 'package:dio/dio.dart';
|
||||
|
||||
class TreezorTokenInterceptor extends Interceptor {
|
||||
TreezorTokenInterceptor({
|
||||
required void Function() onTokenExpired,
|
||||
required void Function() onUnauthorized,
|
||||
}) : _onTokenExpired = onTokenExpired,
|
||||
_onUnauthorized = onUnauthorized;
|
||||
void Function()? onTokenExpired,
|
||||
}) : _onUnauthorized = onUnauthorized,
|
||||
_onTokenExpired = onTokenExpired;
|
||||
|
||||
// ignore: unused_field
|
||||
final void Function() _onTokenExpired;
|
||||
/// Called when the backend signals a session expiration that should
|
||||
/// trigger a re-login flow. The destination route is decided by the
|
||||
/// caller (e.g. SCA screen in payment mode, login screen in legacy
|
||||
/// mode). When `null`, the Treezor-specific detection (message + 500)
|
||||
/// is skipped entirely and only generic 401 responses are handled.
|
||||
final void Function()? _onTokenExpired;
|
||||
|
||||
/// Called on any 401 response. Active in both apps.
|
||||
final void Function() _onUnauthorized;
|
||||
|
||||
bool _handling = false;
|
||||
|
||||
@override
|
||||
void onError(DioException err, ErrorInterceptorHandler handler) {
|
||||
if (!_handling) {
|
||||
// final message = _extractApiMessage(err.response?.data);
|
||||
// if (message != null && message.contains('Treezor Token Expired')) {
|
||||
// _handling = true;
|
||||
// _onTokenExpired();
|
||||
// Future.delayed(const Duration(seconds: 2), () => _handling = false);
|
||||
// }
|
||||
// else if (err.response?.statusCode == 500) {
|
||||
// _handling = true;
|
||||
// _onTokenExpired();
|
||||
// Future.delayed(const Duration(seconds: 2), () => _handling = false);
|
||||
// }
|
||||
// else
|
||||
if (err.response?.statusCode == 401) {
|
||||
// Treezor-specific handling: only enabled when running in payment mode
|
||||
// (i.e. when an `onTokenExpired` callback was provided).
|
||||
if (_onTokenExpired != null) {
|
||||
final message = _extractApiMessage(err.response?.data);
|
||||
if (message != null && message.contains('Treezor Token Expired')) {
|
||||
_handling = true;
|
||||
_onTokenExpired();
|
||||
Future.delayed(
|
||||
const Duration(seconds: 2),
|
||||
() => _handling = false,
|
||||
);
|
||||
} else if (err.response?.statusCode == 500) {
|
||||
_handling = true;
|
||||
_onTokenExpired();
|
||||
Future.delayed(
|
||||
const Duration(seconds: 2),
|
||||
() => _handling = false,
|
||||
);
|
||||
} else if (err.response?.statusCode == 401) {
|
||||
_handling = true;
|
||||
_onUnauthorized();
|
||||
Future.delayed(
|
||||
const Duration(seconds: 2),
|
||||
() => _handling = false,
|
||||
);
|
||||
}
|
||||
} else if (err.response?.statusCode == 401) {
|
||||
_handling = true;
|
||||
_onUnauthorized();
|
||||
Future.delayed(const Duration(seconds: 2), () => _handling = false);
|
||||
@@ -39,7 +60,6 @@ class TreezorTokenInterceptor extends Interceptor {
|
||||
handler.next(err);
|
||||
}
|
||||
|
||||
// ignore: unused_element
|
||||
String? _extractApiMessage(Object? data) {
|
||||
if (data == null) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user