[Solved] Useraccounts: how to clear results message box?


#1

So, I’m using meteor-useraccounts. I’m rolling my own “navBar Menu” because the one that comes with accounts-ui get’s disabled in large part because of useraccounts.

My problem comes when I have a user “reset” a password. It works fine, but then the message stays up there, and I have no way to clear it!? I don’t want to re-direct the user to some other page, because I’m using the form in a modal that pops up to give the user an option to reset the password.

So, then as you see from this picture:

Even if I reset a password, and logout - the “password changed” is still there.

Does anyone know how to clear this results message box?

Thanks,
-Jeremy


[Solved] useraccounts + loginButtons = Broken
#2

There are few methods to clear error or result messages in useraccounts package, one of them should suit your needs:

AccountsTemplates.clearMessage()
AccountsTemplates.clearError();
AccountsTemplates.clearResult();

#3

New problem, same area - There is also the AccountTemplates.clearState() function. My problem is that I need some way of knowing if the password has been reset or not. If I use the onSubmitHook, and then call AccountTemplates.clearState//Error//Message//Result() it will clear the state when the form gets submitted, but the message gets applied after the actual password was reset.

How do I get away from this? Is there a way to watch a reactive var for the message, or a callback for when the password gets reset?

Here is some code to consider.

var hideModalWhenLoggedIn = function(error, state){
  if (!error) {
    if (state === "signIn" || state === "signUp" || state === "changePwd") {
      // Successfully logged in
      // AccountsTemplates.clearState()
      // This hook is being processed onSubmit - which is not waiting for the password to be reset - I need to find a way to hook in AFTER the password has been reset, or somehow watch a reactive var which carries the result and respond to that somehow.
      // Session.set('hideLoginModal', true)
    }
  }
}

AccountsTemplates.configure({
    onSubmitHook: hideModalWhenLoggedIn
})

#4

You can watch for changes on AccountsTemplates.getState(), because IIRC state gets set to from changePwd to signIn AFTER the result gets back from the server.


#5

Is this a reactive source?


#6

Yes, it is a reactive source.


#7

Gosh, I was having all kinds of trouble, and then I finally realized that my problem was the fact that I was calling the form setting the state to “changePwd”… I finally figured out the right way to use things.

I had to setup my own “change password” button - so what I do now is use AccountTemplates.setState("changePwd") and then render my form without setting the state. Somehow the setting of the state was killing the “reactivity” of everything. I’ve been pounding at this for days… FINALLY I got it all working.

Thanks for the great help though.