From 2c86e90b7672f644c26e8c2ae30189d91eb93e02 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 27 Nov 2024 10:54:10 +0100 Subject: [PATCH] login debug --- lib/core/services/auth.service.dart | 3 ++- lib/main.dart | 16 +++++++++------- lib/widgets/dialog/login.dart | 8 ++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/core/services/auth.service.dart b/lib/core/services/auth.service.dart index aef1371..30e1caa 100644 --- a/lib/core/services/auth.service.dart +++ b/lib/core/services/auth.service.dart @@ -3,6 +3,7 @@ import 'package:localstorage/localstorage.dart'; import 'package:oc_front/core/sections/header/header.dart'; import 'package:oc_front/core/services/api_service.dart'; import 'package:oc_front/core/services/perms_service.dart'; +import 'package:oc_front/main.dart'; import 'package:oc_front/models/response.dart'; class AuthService { static var isAuth = const bool.fromEnvironment('AUTH_MODE', defaultValue: false); @@ -60,7 +61,7 @@ class AuthService { static Future logout() async { var token = await service.delete("/ldap/logout", null); - if (token.code == 200 && token.data != null) { + if (token.code == 200) { localStorage.setItem('accessToken', ''); localStorage.setItem('username', ''); localStorage.setItem('expiresIn', ''); diff --git a/lib/main.dart b/lib/main.dart index 55d39ed..e1db18f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -86,14 +86,11 @@ class MainPageState extends State { // // The Flutter framework has been optimized to make rerunning build methods // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. + // than having to individually change instances of widgets.i scaffoldKey = GlobalKey(); isCtrl = false; - return FutureBuilder(future: AuthService.init(), - builder: (e, s) { - WorkspaceLocal.init(context, false); - CollaborativeAreaLocal.init(context, false); - if (!AuthService.isConnected()) { + if (!AuthService.isConnected()) { + print("isConnected: ${AuthService.isConnected()}"); Future.delayed(const Duration(milliseconds: 500), () { showDialog( barrierDismissible: false, @@ -105,7 +102,12 @@ class MainPageState extends State { title: LoginWidget()); }); }); - } + } + return FutureBuilder(future: AuthService.init(), + builder: (e, s) { + WorkspaceLocal.init(context, false); + CollaborativeAreaLocal.init(context, false); + HeaderConstants.height = HeaderConstants.isNoHeader(AppRouter.currentRoute.route) || AppRouter.currentRoute.factory.searchFill() ? 50 : 100; return Scaffold( key: scaffoldKey, endDrawer: EndDrawerWidget(), body: SingleChildScrollView( diff --git a/lib/widgets/dialog/login.dart b/lib/widgets/dialog/login.dart index 53e2c29..ac08d3f 100644 --- a/lib/widgets/dialog/login.dart +++ b/lib/widgets/dialog/login.dart @@ -18,24 +18,23 @@ class LoginWidgetState extends State { FocusNode focusNode = FocusNode(); @override Widget build(BuildContext context) { return KeyboardListener(focusNode: focusNode, - onKeyEvent: (value) { + onKeyEvent: (value) async { if (value is KeyDownEvent && value.logicalKey == LogicalKeyboardKey.enter) { if (usernameCtrl.text == "" || passwordCtrl.text == "") { return; } error = null; setState(() { loading = true; }); - AuthService.login(usernameCtrl.text, passwordCtrl.text).catchError( (e) { + await AuthService.login(usernameCtrl.text, passwordCtrl.text).catchError( (e) { setState(() { loading = false; error = "Invalid username or password"; }); }); - if (error == null) { // ignore: use_build_context_synchronously setState(() { - loading = true; + loading = false; }); context.pop(); } @@ -114,6 +113,7 @@ class LoginWidgetState extends State { loading = true; }); context.pop(); + //mainKey?.currentState!.setState(() {}); } }, mouseCursor: SystemMouseCursors.click,