mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 04:48:51 +00:00
Open login page if login tokens are rejected by server
This commit is contained in:
parent
159e7228bf
commit
5eaf8d6b72
@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:comunic/helpers/events_helper.dart';
|
||||
import 'package:comunic/helpers/preferences_helper.dart';
|
||||
import 'package:comunic/models/api_request.dart';
|
||||
import 'package:comunic/models/api_response.dart';
|
||||
@ -71,6 +72,10 @@ class APIHelper {
|
||||
),
|
||||
);
|
||||
|
||||
// Check if login token is rejected by server
|
||||
if (response.statusCode == 412)
|
||||
EventsHelper.emit(InvalidLoginTokensEvent());
|
||||
|
||||
if (response.statusCode != HttpStatus.ok)
|
||||
return APIResponse(response.statusCode, null);
|
||||
|
||||
|
@ -8,6 +8,9 @@ import 'package:event_bus/event_bus.dart';
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
/// Invalid login token
|
||||
class InvalidLoginTokensEvent {}
|
||||
|
||||
/// Main WebSocket closed
|
||||
class WSClosedEvent {}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:comunic/helpers/events_helper.dart';
|
||||
import 'package:comunic/helpers/websocket_helper.dart';
|
||||
import 'package:comunic/ui/routes/login_route.dart';
|
||||
import 'package:comunic/ui/routes/main_route.dart';
|
||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
@ -28,6 +29,9 @@ class _InitializeWidgetState extends SafeState<InitializeWidget> {
|
||||
|
||||
super.initState();
|
||||
|
||||
// Check if login token are considered as invalid
|
||||
super.listen<InvalidLoginTokensEvent>((ev) => _openLoginPage());
|
||||
|
||||
// Listen to WebSocket close event
|
||||
super.listen<WSClosedEvent>((e) => _tryConnect());
|
||||
}
|
||||
@ -38,6 +42,12 @@ class _InitializeWidgetState extends SafeState<InitializeWidget> {
|
||||
WebSocketHelper.close();
|
||||
}
|
||||
|
||||
/// Open login page
|
||||
_openLoginPage() {
|
||||
Navigator.of(context)
|
||||
.pushReplacement(MaterialPageRoute(builder: (c) => LoginRoute()));
|
||||
}
|
||||
|
||||
/// Try to connect to server
|
||||
void _tryConnect() async {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user