From a779d507d4515f99a0c822e95f7acbfda8fe148a Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 29 Nov 2023 16:21:39 +0100 Subject: [PATCH] fix: reset settings when navigating back --- .../lib/blocs/settings/settings_bloc.dart | 10 +++++----- .../lib/blocs/settings/settings_event.dart | 2 +- flutter-ory-network/lib/pages/settings.dart | 15 ++++++++------- flutter-ory-network/lib/services/auth.dart | 4 ++++ flutter-ory-network/lib/widgets/helpers.dart | 2 ++ flutter-ory-network/pubspec.lock | 4 ++-- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart index 39b22dbf..345d47a6 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart @@ -26,7 +26,7 @@ class SettingsBloc extends Bloc { on(_onCreateSettingsFlow); on(_onGetSettingsFlow); on(_onChangeNodeValue, transformer: sequential()); - on(_onResetButtonValues); + on(_onResetSettings); on(_onUpdateSettingsFlow, transformer: sequential()); } @@ -51,13 +51,13 @@ class SettingsBloc extends Bloc { } } - _onResetButtonValues(ResetButtonValues event, Emitter emit) { + _onResetSettings(ResetSettings event, Emitter emit) async { if (state.settingsFlow != null) { emit(state.copyWith(isLoading: true)); - final updatedSettings = - repository.resetButtonValues(settingsFlow: state.settingsFlow!); + final settings = + await repository.getSettingsFlow(flowId: state.settingsFlow!.id); emit(state.copyWith( - settingsFlow: updatedSettings, + settingsFlow: settings, isSessionRefreshRequired: false, isLoading: false)); } diff --git a/flutter-ory-network/lib/blocs/settings/settings_event.dart b/flutter-ory-network/lib/blocs/settings/settings_event.dart index e1c7539f..fbecd5eb 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_event.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_event.dart @@ -28,7 +28,7 @@ class ChangeSettingsNodeValue extends SettingsEvent { List get props => [value, name]; } -class ResetButtonValues extends SettingsEvent {} +class ResetSettings extends SettingsEvent {} class UpdateSettingsFlow extends SettingsEvent { final UiNodeGroupEnum group; diff --git a/flutter-ory-network/lib/pages/settings.dart b/flutter-ory-network/lib/pages/settings.dart index 18f4dcd5..fb5553b9 100644 --- a/flutter-ory-network/lib/pages/settings.dart +++ b/flutter-ory-network/lib/pages/settings.dart @@ -85,9 +85,8 @@ class SettingsForm extends StatelessWidget { } } else { // if user goes back without finishing login, - // reset button values to prevent submitting values that - // were selected prior to session refresh navigation - settingsBloc.add(ResetButtonValues()); + // reset settings + settingsBloc.add(ResetSettings()); } }); } @@ -97,11 +96,13 @@ class SettingsForm extends StatelessWidget { BlocListener( bloc: settingsBloc, listenWhen: (SettingsState previous, SettingsState current) => - // listen to changes only when previous - // state was loading (e.g. updating settings), - // current state is not loading and session refresh is not required - previous.isLoading != current.isLoading && + // listen to changes only when current + // state is not loading (e.g. updating settings), + // previous and current messages differ + // and session refresh is not required !current.isLoading && + current.settingsFlow?.ui.messages != + previous.settingsFlow?.ui.messages && !current.isSessionRefreshRequired, listener: (BuildContext context, SettingsState state) { if (state.settingsFlow!.ui.messages != null) { diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index 0714b164..a07afc50 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -390,6 +390,10 @@ class AuthService { if (e.response?.statusCode == 401) { await _storage.deleteToken(); throw const CustomException.unauthorized(); + } else if (e.response?.statusCode == 410) { + // settings flow expired, use new flow id + throw CustomException.flowExpired( + flowId: e.response?.data['use_flow_id']); } else { throw _handleUnknownException(e.response?.data); } diff --git a/flutter-ory-network/lib/widgets/helpers.dart b/flutter-ory-network/lib/widgets/helpers.dart index f6862ac7..aead4992 100644 --- a/flutter-ory-network/lib/widgets/helpers.dart +++ b/flutter-ory-network/lib/widgets/helpers.dart @@ -127,6 +127,8 @@ List getNodesOfGroup(UiNodeGroupEnum group, BuiltList nodes) { } else { return true; } + } else { + return true; } } } diff --git a/flutter-ory-network/pubspec.lock b/flutter-ory-network/pubspec.lock index 85d0b9a4..171eb735 100644 --- a/flutter-ory-network/pubspec.lock +++ b/flutter-ory-network/pubspec.lock @@ -580,10 +580,10 @@ packages: dependency: "direct main" description: name: ory_client - sha256: c8d672ee192c77aa4231afbbf7fa6d23387e2a09ac9cf14a596dfcf5b0ecc29b + sha256: "6d6ec2304afd9c20489f2a8118b4cddfbdae4fc22915bd9a168a777620af5c44" url: "https://pub.dev" source: hosted - version: "1.2.16" + version: "1.4.3" package_config: dependency: transitive description: