Reputation: 20761
I've a small issue: I'm using the NgxsStoragePluginModule to persists my states accross refreshes.
But in my AuthState, I do set the authError
, if the login wasn't successfull.
One case could be a wrong password, other could be that I've to much trials.
Then, if I refresh the page, I would expect to not have any auth error on this page, the user is not even trying to login.
I've checked the documentation(https://www.ngxs.io/plugins/storage), but they only mention how to exclude from storage one state, but they don't say anything about how to exclude one property of the state.
Here is how I update this authError:
@Action(LoginWithPasswordAction)
async loginWithPassword(ctx: StateContext<AuthStateModel>, action: LoginWithPasswordAction) {
ctx.patchState({
authError: null,
});
try {
await this.angularFireAuth.signInWithEmailAndPassword(action.email, action.password);
await this.router.navigate(['/']);
} catch (exception) {
console.log('Login Setting exception to'+exception.message)
ctx.patchState({
authError: exception.message,
});
}
}
I tried to patch the state with a null error in the ngxsOnInit, but it seems it doesn't work.
I could put this in another state, but since it's "auth" related, I was thinking it was quite logical to have it here.
Does anybody have an idea how to prevent it from being saved? Or at least reset it when I reload?
Upvotes: 2
Views: 244