From 56ce747ffc61723aac2730ba3f9af54d601cd734 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 21 Nov 2022 05:29:43 -0600 Subject: [PATCH] fix(mobile): freeze on splash screen due to accessing bad state (#998) --- .../providers/authentication.provider.dart | 11 +++--- mobile/lib/modules/login/ui/login_form.dart | 1 + mobile/lib/shared/views/splash_screen.dart | 34 ++++++++++-------- .../openapi/lib/model/asset_response_dto.dart | Bin 9013 -> 9208 bytes .../openapi/lib/model/user_response_dto.dart | Bin 5587 -> 5742 bytes 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/mobile/lib/modules/login/providers/authentication.provider.dart b/mobile/lib/modules/login/providers/authentication.provider.dart index 89202f838a..1864d0e024 100644 --- a/mobile/lib/modules/login/providers/authentication.provider.dart +++ b/mobile/lib/modules/login/providers/authentication.provider.dart @@ -90,6 +90,7 @@ class AuthenticationNotifier extends StateNotifier { return setSuccessLoginInfo( accessToken: loginResponse.accessToken, + serverUrl: serverEndpoint, isSavedLoginInfo: isSavedLoginInfo, ); } catch (e) { @@ -159,16 +160,18 @@ class AuthenticationNotifier extends StateNotifier { Future setSuccessLoginInfo({ required String accessToken, + required String serverUrl, required bool isSavedLoginInfo, }) async { - Hive.box(userInfoBox).put(accessTokenKey, accessToken); - _apiService.setAccessToken(accessToken); var userResponseDto = await _apiService.userApi.getMyUserInfo(); if (userResponseDto != null) { + var userInfoHiveBox = await Hive.openBox(userInfoBox); var deviceInfo = await _deviceInfoService.getDeviceInfo(); - Hive.box(userInfoBox).put(deviceIdKey, deviceInfo["deviceId"]); + userInfoHiveBox.put(deviceIdKey, deviceInfo["deviceId"]); + userInfoHiveBox.put(accessTokenKey, accessToken); + userInfoHiveBox.put(serverEndpointKey, serverUrl); state = state.copyWith( isAuthenticated: true, @@ -191,7 +194,7 @@ class AuthenticationNotifier extends StateNotifier { email: "", password: "", isSaveLogin: true, - serverUrl: Hive.box(userInfoBox).get(serverEndpointKey), + serverUrl: serverUrl, accessToken: accessToken, ), ); diff --git a/mobile/lib/modules/login/ui/login_form.dart b/mobile/lib/modules/login/ui/login_form.dart index 82f723f01e..a1c32f80d7 100644 --- a/mobile/lib/modules/login/ui/login_form.dart +++ b/mobile/lib/modules/login/ui/login_form.dart @@ -380,6 +380,7 @@ class OAuthLoginButton extends ConsumerWidget { .setSuccessLoginInfo( accessToken: loginResponseDto.accessToken, isSavedLoginInfo: isSavedLoginInfo, + serverUrl: serverEndpointController.text, ); if (isSuccess) { diff --git a/mobile/lib/shared/views/splash_screen.dart b/mobile/lib/shared/views/splash_screen.dart index b62e5d6b09..e659c1241a 100644 --- a/mobile/lib/shared/views/splash_screen.dart +++ b/mobile/lib/shared/views/splash_screen.dart @@ -20,22 +20,28 @@ class SplashScreenPage extends HookConsumerWidget { Hive.box(hiveLoginInfoBox).get(savedLoginInfoKey); void performLoggingIn() async { - if (loginInfo != null) { - // Make sure API service is initialized - apiService.setEndpoint(loginInfo.serverUrl); + try { + if (loginInfo != null) { + // Make sure API service is initialized + apiService.setEndpoint(loginInfo.serverUrl); - var isSuccess = - await ref.read(authenticationProvider.notifier).setSuccessLoginInfo( - accessToken: loginInfo.accessToken, - isSavedLoginInfo: true, - ); - if (isSuccess) { - // Resume backup (if enable) then navigate - ref.watch(backupProvider.notifier).resumeBackup(); - AutoRouter.of(context).replace(const TabControllerRoute()); - } else { - AutoRouter.of(context).replace(const LoginRoute()); + var isSuccess = await ref + .read(authenticationProvider.notifier) + .setSuccessLoginInfo( + accessToken: loginInfo.accessToken, + isSavedLoginInfo: true, + serverUrl: loginInfo.serverUrl, + ); + if (isSuccess) { + // Resume backup (if enable) then navigate + ref.watch(backupProvider.notifier).resumeBackup(); + AutoRouter.of(context).replace(const TabControllerRoute()); + } else { + AutoRouter.of(context).replace(const LoginRoute()); + } } + } catch (_) { + AutoRouter.of(context).replace(const LoginRoute()); } } diff --git a/mobile/openapi/lib/model/asset_response_dto.dart b/mobile/openapi/lib/model/asset_response_dto.dart index 164a426dc103d23997d17babf675888cac06d07e..f916088ba26543b3b67794c6c50546debace41d1 100644 GIT binary patch delta 528 zcmdn$_QQR{U3NAu1rV5gmt6|R{LZdCS(HOzvH^$8WOoju$t4_Wlc#cMOy0p^F!?cu z&SWl5t;zbFI+MeIxRz66@&X_}48+ekEhbBHX-u}^(wdye6)|}`m*(VqToNJ*3L2Ry zdKrnu8P54BshSGfKr1J+aVtv#CGyMjQj0t>WbL@+CP#5AOs?Rzn7oc#cJfJXIT?^K z#cqjZ`9+x}sp!W2=Qf*c%p)_|m&assJ&()egFyN-kJ)5(-Xy5EHh1zqW}KYIFD)FO zRh*v}U8J6wq8_VYtB{#u%{6%ezv1M|{ECym@heZ37FaR)sDSF^Hv;ODMFr<<-YmG2 zMO@1GA}VVGg$%T5FMy#llc_Hn1QmJYh;?4@hf8iDyyCRURHMUb$Rj0kqS5L qpmu>`GBvNHs8X*iF{d0DJRuR0meeeZVps@%m@H~*q0js delta 437 zcmZutO-mbL5GE+N*$>?Wlhj1(*d^Ir6H-V^50;=bReylq#I~#Z;;tlF*^jotc*qEFCJ77FRxOx3liUgv5ml|-xvHS7ozIO38kp^RKoM$dVXW{}zB^|R;RyAC^>R5r(@N8yMS%fEP*p^1HFXiz|dWdW3 z88o?o8F>`1IJ$BT2XY?2<=SWE1zsvOyjPxLPk9p$4_+n;M6cHauf62!VP}Ks%T%Wx zc`g!RP%S`LA7fF~5UE9cQFk$u(!o+DKBm6KM*3%e$_fJJhlXL&Chy^fn`{YM&cUag z!^17JH|xLoER6g%g?@CqfG6Ye2PgeQcBgH%+*RsbQlU+Jr)-=V`_Ol9;hdBN@%Q_k f>RYQBu?nsE-aBih$)@gD1;=BP@${n~iG=tMoU4kE diff --git a/mobile/openapi/lib/model/user_response_dto.dart b/mobile/openapi/lib/model/user_response_dto.dart index a6242d2c8411dc4e66c27c2fa6043c553fb2308c..63c176378fe413d055c07013c9612d29f6868e7a 100644 GIT binary patch delta 503 zcmcbt{Z3~?4Ko{;0tig5VU~h1r!gzZfCckQGE$55GE)?6Z54o|ni^E?DQ2a~&zZF* z^RQ@4)@RY09KvETxt+yf@*x(r$&XpQCTp{5P7Y!f6IW2sNX<>m%+bq8EY5JwPf68O z&;}YYxtdje@(fm)$(vYZC!b|inf#trLlUSqv)C~uH!}}iwGLYt)McBS*bEpaZ($do ze3o5y@*8&5$-*4UlPx$@C&zObPoBbIz4;=?9wu>peTBs0;?$xN4Gm3&YKWT^^z|pt z<5pt=Qir)SK$I3wh9*#@f nZbmyK2c+he6jkb#CFYcZ%>}y&NWkp0g0n!jLcr#5k!nT&Zy|`{ delta 360 zcmZutyGp}Q043&OjMdtQg;u1um9_~DMG+A!oy1vi6I{~f+ClGIY0;@}sQ^9SMw z2$@6?+}s>QoCG%~-K7r32Tq>lJg4)f-dE29Hb+dI+P>M+EZH|qPbH3TP*)*AfK#@Z z{B|`{Cyhq5B;~S%XSRq*u7nkC3A+)WaI3iF>KJnc6!^H7mT(;LnYe~W zu@NSxt|t<0#gS>`