1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-07 20:36:48 +01:00

fix(mobile): freeze on splash screen due to accessing bad state (#998)

This commit is contained in:
Alex 2022-11-21 05:29:43 -06:00 committed by GitHub
parent a2f3b2199a
commit 56ce747ffc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 18 deletions

View file

@ -90,6 +90,7 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
return setSuccessLoginInfo( return setSuccessLoginInfo(
accessToken: loginResponse.accessToken, accessToken: loginResponse.accessToken,
serverUrl: serverEndpoint,
isSavedLoginInfo: isSavedLoginInfo, isSavedLoginInfo: isSavedLoginInfo,
); );
} catch (e) { } catch (e) {
@ -159,16 +160,18 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
Future<bool> setSuccessLoginInfo({ Future<bool> setSuccessLoginInfo({
required String accessToken, required String accessToken,
required String serverUrl,
required bool isSavedLoginInfo, required bool isSavedLoginInfo,
}) async { }) async {
Hive.box(userInfoBox).put(accessTokenKey, accessToken);
_apiService.setAccessToken(accessToken); _apiService.setAccessToken(accessToken);
var userResponseDto = await _apiService.userApi.getMyUserInfo(); var userResponseDto = await _apiService.userApi.getMyUserInfo();
if (userResponseDto != null) { if (userResponseDto != null) {
var userInfoHiveBox = await Hive.openBox(userInfoBox);
var deviceInfo = await _deviceInfoService.getDeviceInfo(); 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( state = state.copyWith(
isAuthenticated: true, isAuthenticated: true,
@ -191,7 +194,7 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
email: "", email: "",
password: "", password: "",
isSaveLogin: true, isSaveLogin: true,
serverUrl: Hive.box(userInfoBox).get(serverEndpointKey), serverUrl: serverUrl,
accessToken: accessToken, accessToken: accessToken,
), ),
); );

View file

@ -380,6 +380,7 @@ class OAuthLoginButton extends ConsumerWidget {
.setSuccessLoginInfo( .setSuccessLoginInfo(
accessToken: loginResponseDto.accessToken, accessToken: loginResponseDto.accessToken,
isSavedLoginInfo: isSavedLoginInfo, isSavedLoginInfo: isSavedLoginInfo,
serverUrl: serverEndpointController.text,
); );
if (isSuccess) { if (isSuccess) {

View file

@ -20,14 +20,17 @@ class SplashScreenPage extends HookConsumerWidget {
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).get(savedLoginInfoKey); Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).get(savedLoginInfoKey);
void performLoggingIn() async { void performLoggingIn() async {
try {
if (loginInfo != null) { if (loginInfo != null) {
// Make sure API service is initialized // Make sure API service is initialized
apiService.setEndpoint(loginInfo.serverUrl); apiService.setEndpoint(loginInfo.serverUrl);
var isSuccess = var isSuccess = await ref
await ref.read(authenticationProvider.notifier).setSuccessLoginInfo( .read(authenticationProvider.notifier)
.setSuccessLoginInfo(
accessToken: loginInfo.accessToken, accessToken: loginInfo.accessToken,
isSavedLoginInfo: true, isSavedLoginInfo: true,
serverUrl: loginInfo.serverUrl,
); );
if (isSuccess) { if (isSuccess) {
// Resume backup (if enable) then navigate // Resume backup (if enable) then navigate
@ -37,6 +40,9 @@ class SplashScreenPage extends HookConsumerWidget {
AutoRouter.of(context).replace(const LoginRoute()); AutoRouter.of(context).replace(const LoginRoute());
} }
} }
} catch (_) {
AutoRouter.of(context).replace(const LoginRoute());
}
} }
useEffect( useEffect(