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 164a426dc1..f916088ba2 100644 Binary files a/mobile/openapi/lib/model/asset_response_dto.dart and b/mobile/openapi/lib/model/asset_response_dto.dart differ diff --git a/mobile/openapi/lib/model/user_response_dto.dart b/mobile/openapi/lib/model/user_response_dto.dart index a6242d2c84..63c176378f 100644 Binary files a/mobile/openapi/lib/model/user_response_dto.dart and b/mobile/openapi/lib/model/user_response_dto.dart differ