Improved credential checking for CheckupPage
This commit is contained in:
parent
2c1ad486df
commit
529ec239d1
1 changed files with 17 additions and 6 deletions
|
|
@ -2,6 +2,7 @@ import 'package:animated_background/animated_background.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:tuuli_app/api/api_client.dart';
|
||||
|
||||
class CheckupPage extends StatefulWidget {
|
||||
const CheckupPage({super.key});
|
||||
|
|
@ -16,13 +17,8 @@ class _CheckupPageState extends State<CheckupPage>
|
|||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final accessToken = GetStorage().read<String?>("accessToken");
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (accessToken == null) {
|
||||
Get.offAllNamed("/login");
|
||||
} else {
|
||||
Get.offAllNamed("/home");
|
||||
}
|
||||
checkCredentials();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -51,4 +47,19 @@ class _CheckupPageState extends State<CheckupPage>
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> checkCredentials() async {
|
||||
final accessToken = GetStorage().read<String?>("accessToken");
|
||||
if (accessToken == null) {
|
||||
Get.offAllNamed("/login");
|
||||
} else {
|
||||
final apiClient = Get.find<ApiClient>();
|
||||
(await apiClient.tablesList()).unfold((data) {
|
||||
Get.offAllNamed("/home");
|
||||
}, (error) async {
|
||||
await GetStorage().remove("accessToken");
|
||||
Get.offAllNamed("/login");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue