studiointeract / accounts-ui

Accounts UI for React in Meteor 1.3+
MIT License
196 stars 80 forks source link

Sign out? #121

Open AnthonyLamot opened 7 years ago

AnthonyLamot commented 7 years ago

This is probably a very basic question, but it's not mentioned in the doc how a logout button can be added.

When using Meteor's accounts, after logging in, the log out button is automatically displayed.

I tried several things but couldn't figure out how to display it. Help much appreciated!

ianchanning commented 7 years ago

Something doesn't appear to be working - the form should do as you suspect and show the 'profile' information once you are logged in.

If you look at the LoginForm.jsx, the following code is run when you successfully login:

    if (!error) {
      Meteor.loginWithPassword(loginSelector, password, (error, result) => {
        onSubmitHook(error,formState);
        if (error) {
          this.showMessage(`error.accounts.${error.reason}` || "unknown_error", 'error');
        }
        else {
          loginResultCallback(() => this.state.onSignedInHook());
          this.setState({
            formState: STATES.PROFILE,
            password: null,
          });
          this.clearDefaultFieldValues();
        }
      });
}

This sets the state to formState: STATES.PROFILE.

So then the LoginForm should display the Change Password and Sign Out buttons. But for me, the form is blank.

ianchanning commented 7 years ago

And indeed in the LoginFom.jsx buttons() function, there is the following code which should add the Sign Out button:

    if (user && formState == STATES.PROFILE) {
      loginButtons.push({
        id: 'signOut',
        label: this.translate('signOut'),
        disabled: waiting,
        onClick: this.signOut.bind(this)
      });
}
AnthonyLamot commented 7 years ago

@ianchanning thanks for confirming what I suspected.

In the meantime I've moved on to simply using the Meteor-provided accounts functions to let users sign up / sign in / log out, which I built into forms / buttons of my own making. It seems a more robust approach anyway and you have more control.

Of course, if this package would work it could make building mock-ups a lot faster.

ianchanning commented 7 years ago

I've essentially worked around the problem by using NavBar buttons instead.

From what I can tell #117 appears to be a related bug and the PR for that looks promising.