fix(mobile): user get logged out upon clicking on any thing after logging in (#1808)

* fix(mobile): user get logged out upon clicking on any thing after logging in

* wip: fixing still

* fix: the actual issue

* Fix: avaialble album not updating UI
This commit is contained in:
Alex
2023-02-20 21:43:39 -06:00
committed by GitHub
parent 03d484aba2
commit 98998cccbc
11 changed files with 137 additions and 117 deletions

View File

@@ -92,20 +92,25 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
}
Future<bool> logout() async {
await Future.wait([
_apiService.authenticationApi.logout(),
Hive.box(userInfoBox).delete(accessTokenKey),
Store.delete(StoreKey.assetETag),
Store.delete(StoreKey.userRemoteId),
_assetCacheService.invalidate(),
_albumCacheService.invalidate(),
_sharedAlbumCacheService.invalidate(),
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).delete(savedLoginInfoKey)
]);
try {
await Future.wait([
_apiService.authenticationApi.logout(),
Hive.box(userInfoBox).delete(accessTokenKey),
Store.delete(StoreKey.assetETag),
Store.delete(StoreKey.userRemoteId),
_assetCacheService.invalidate(),
_albumCacheService.invalidate(),
_sharedAlbumCacheService.invalidate(),
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).delete(savedLoginInfoKey)
]);
state = state.copyWith(isAuthenticated: false);
state = state.copyWith(isAuthenticated: false);
return true;
return true;
} catch (e) {
debugPrint("Error logging out $e");
return false;
}
}
setAutoBackup(bool backupState) async {

View File

@@ -68,7 +68,28 @@ class ChangePasswordForm extends HookConsumerWidget {
),
ChangePasswordButton(
passwordController: passwordController,
formKey: formKey,
onPressed: () async {
if (formKey.currentState!.validate()) {
var isSuccess = await ref
.read(authenticationProvider.notifier)
.changePassword(passwordController.value.text);
if (isSuccess) {
bool res = await ref
.read(authenticationProvider.notifier)
.logout();
if (res) {
ref.read(backupProvider.notifier).cancelBackup();
ref.read(assetProvider.notifier).clearAllAsset();
ref.read(websocketProvider.notifier).disconnect();
AutoRouter.of(context)
.replace(const LoginRoute());
}
}
}
},
),
],
),
@@ -122,7 +143,7 @@ class ConfirmPasswordInput extends StatelessWidget {
return TextFormField(
obscureText: true,
controller: confirmController,
decoration: InputDecoration(
decoration: InputDecoration(
labelText: 'change_password_form_confirm_password'.tr(),
hintText: 'change_password_form_reenter_new_password'.tr(),
border: const OutlineInputBorder(),
@@ -135,12 +156,11 @@ class ConfirmPasswordInput extends StatelessWidget {
class ChangePasswordButton extends ConsumerWidget {
final TextEditingController passwordController;
final GlobalKey<FormState> formKey;
final VoidCallback onPressed;
const ChangePasswordButton({
Key? key,
required this.passwordController,
required this.formKey,
required this.onPressed,
}) : super(key: key);
@override
@@ -153,25 +173,7 @@ class ChangePasswordButton extends ConsumerWidget {
elevation: 2,
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 25),
),
onPressed: () async {
if (formKey.currentState!.validate()) {
var isSuccess = await ref
.watch(authenticationProvider.notifier)
.changePassword(passwordController.value.text);
if (isSuccess) {
bool res =
await ref.watch(authenticationProvider.notifier).logout();
if (res) {
ref.watch(backupProvider.notifier).cancelBackup();
ref.watch(assetProvider.notifier).clearAllAsset();
ref.watch(websocketProvider.notifier).disconnect();
AutoRouter.of(context).replace(const LoginRoute());
}
}
}
},
onPressed: onPressed,
child: Text(
'common_change_password'.tr(),
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold),

View File

@@ -298,10 +298,10 @@ class LoginButton extends ConsumerWidget {
),
onPressed: () async {
// This will remove current cache asset state of previous user login.
ref.watch(assetProvider.notifier).clearAllAsset();
ref.read(assetProvider.notifier).clearAllAsset();
var isAuthenticated =
await ref.watch(authenticationProvider.notifier).login(
await ref.read(authenticationProvider.notifier).login(
emailController.text,
passwordController.text,
serverEndpointController.text,
@@ -309,12 +309,11 @@ class LoginButton extends ConsumerWidget {
if (isAuthenticated) {
// Resume backup (if enable) then navigate
if (ref.watch(authenticationProvider).shouldChangePassword &&
!ref.watch(authenticationProvider).isAdmin) {
if (ref.read(authenticationProvider).shouldChangePassword &&
!ref.read(authenticationProvider).isAdmin) {
AutoRouter.of(context).push(const ChangePasswordRoute());
} else {
ref.watch(backupProvider.notifier).resumeBackup();
ref.read(backupProvider.notifier).resumeBackup();
AutoRouter.of(context).replace(const TabControllerRoute());
}
} else {