mirror of
https://github.com/immich-app/immich.git
synced 2025-01-06 11:56:46 +01:00
fix(mobile): freeze on splash screen due to accessing bad state (#998)
This commit is contained in:
parent
a2f3b2199a
commit
56ce747ffc
5 changed files with 28 additions and 18 deletions
|
@ -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,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -20,22 +20,28 @@ class SplashScreenPage extends HookConsumerWidget {
|
||||||
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).get(savedLoginInfoKey);
|
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).get(savedLoginInfoKey);
|
||||||
|
|
||||||
void performLoggingIn() async {
|
void performLoggingIn() async {
|
||||||
if (loginInfo != null) {
|
try {
|
||||||
// Make sure API service is initialized
|
if (loginInfo != null) {
|
||||||
apiService.setEndpoint(loginInfo.serverUrl);
|
// Make sure API service is initialized
|
||||||
|
apiService.setEndpoint(loginInfo.serverUrl);
|
||||||
|
|
||||||
var isSuccess =
|
var isSuccess = await ref
|
||||||
await ref.read(authenticationProvider.notifier).setSuccessLoginInfo(
|
.read(authenticationProvider.notifier)
|
||||||
accessToken: loginInfo.accessToken,
|
.setSuccessLoginInfo(
|
||||||
isSavedLoginInfo: true,
|
accessToken: loginInfo.accessToken,
|
||||||
);
|
isSavedLoginInfo: true,
|
||||||
if (isSuccess) {
|
serverUrl: loginInfo.serverUrl,
|
||||||
// Resume backup (if enable) then navigate
|
);
|
||||||
ref.watch(backupProvider.notifier).resumeBackup();
|
if (isSuccess) {
|
||||||
AutoRouter.of(context).replace(const TabControllerRoute());
|
// Resume backup (if enable) then navigate
|
||||||
} else {
|
ref.watch(backupProvider.notifier).resumeBackup();
|
||||||
AutoRouter.of(context).replace(const LoginRoute());
|
AutoRouter.of(context).replace(const TabControllerRoute());
|
||||||
|
} else {
|
||||||
|
AutoRouter.of(context).replace(const LoginRoute());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (_) {
|
||||||
|
AutoRouter.of(context).replace(const LoginRoute());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue