-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Password in Redux State. #63
Comments
Also, how to store the data in the state? I mean, if I want to update the password after every change, I should to write something like this: `` final fun = () => store.dispatch(new LoginOrPasswordChangedAction(_emailController.text, _passController.text));
_emailController.addListener(fun);
_passController.addListener(fun); But in this case, after each change, I lose the TextField focus. |
And last question. How to invoke action before another? Should I do it? For example (redux epic): Stream<dynamic> logoutEpic(Stream<LogOutAction> actions, EpicStore<AppState> store) async* {
await for (dynamic action in actions) {
if(action is LogOutAction) {
yield new PrepareLogOutAction();
//wait while all middlewares handle it.
yield new FirebaseLogOutAction();
}
}
} I need to remove device id from firestore before user logs out to stop FCM. |
Hey there, thanks for writing! Let me see if I can take your Qs one at a time.
Overall, I'd personally avoid storing passwords in the State class if you can, for simple security purposes. You might forget to clear this password, or accidentally persist it somewhere, etc. I'm curious: What is causing the Username & Password fields to be reset when you tap the Login button? I don't see the
I generally think the approach of sending 1
I'd probably just dispatch one action in this case... not quite sure what splitting this one action into 2 actions gives you? |
Thank you for response.
Ok, thank you.
I want to split middelwares logic, what I mean: |
Ah, I gotcha. Yah, in that case, you could definitely dispatch two actions to fulfill that requirement, or consider some Actions as more "Common Actions" that could affect multiple parts of your State tree, such as Logout actions. I don't mind having some "Common Actions" that are handled by different reducers / middleware, since it's generally a bit easier to work with. That said, if you like the idea of dispatching two actions, no problem at all, you'll just need to do a bit more coordination. In this case, the // Assumes you're using a TypedEpic for PrepareLogoutActions
Stream<dynamic> logoutEpic(Stream<PrepareLogoutAction> actions, EpicStore<AppState> store) async* {
await for (PrepareLogoutAction action in actions) {
await database.deleteUser(action.user);
action.completer.complete();
}
} Then, inside your Epic function that coordinates all of this, you could do something like this: // This assumes you're using a TypedEpic, which will narrow the actions down to only LogOutAction
Stream<dynamic> logoutEpic(Stream<LogOutAction> actions, EpicStore<AppState> store) async* {
await for (LogoutAction action in actions) {
final initialAction = PrepareLogoutAction();
yield initialAction;
// Await for the initialAction to be completed by the middleware
await initialAction.completer.future;
// Then dispatch the FirebaseLogoutAction
yield new FirebaseLogOutAction();
}
} That said, I think this would all be a bit less entangled if you just assume some actions are "Common Actions," and each middleware can handle the action however it wants, without depending on the ordering of the actions. If you need to wait until the first cleanup action finishes before doing the second, the completer solution might be an option, or putting all of this logic into 1 epic might be another option. Then you could just do: Stream<dynamic> cleanupEpic(Stream<LogoutAction> actions, EpicStore<AppState> store) async* {
await for (LogoutAction action in actions) {
await database.deleteUser(action.user);
await firebase.deleteUser(action.user);
}
} That might go against your design philosophy, but I think there are pros and cons to each approach. Hope that helps! |
Thank you again for helping! I think that 'Common actions' is a good approach, despite some cons. |
I have
AuthState
withfirebaseAuth
field. I have a widget calledLoginPage
, that have state and viewmodel. But when I click Login button, login and password are flushing (TextFormFields becames empty). Should I store password and login in the redux state to restore them in viewmodel? Is it safe?The text was updated successfully, but these errors were encountered: