Skip to content
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

Login/Signup/Recover/Reset accessible after authentication #18

Open
inkiltie opened this issue Jun 3, 2021 · 1 comment
Open

Login/Signup/Recover/Reset accessible after authentication #18

inkiltie opened this issue Jun 3, 2021 · 1 comment

Comments

@inkiltie
Copy link

inkiltie commented Jun 3, 2021

Describe the bug
If you manually type /login, /signup, /recover-password in URL address while being authenticated you will be directed to these pages and stay on them without any redirect. this.props.isLoggedIn is undefined in this case in PublicRoute.js.

Same thing works if you click on "Reset Password" in the email let's say for the second time, you also land on /reset-password/token while being authenticated.

Is it because of local state, slow Redux or something else? In Meteor Pup it was easy cause userId was built-in and always there.

To Reproduce
Steps to reproduce the behavior:

  1. Go to localhost:5000/documents
  2. Type localhost:5000/login in URL

Expected behavior
Redirect to default authenticated page without loading 'Login' page UI

Desktop (please complete the following information):

  • OS: MacOS 11.4
  • Browser Chrome
  • Version 90.0.4430.212
@inkiltie inkiltie changed the title Login/Signup/Recover accessible after authentication Login/Signup/Recover/Reset accessible after authentication Jun 4, 2021
@inkiltie
Copy link
Author

inkiltie commented Aug 14, 2021

I simply solved this issue by adding await before loginWithToken() here:

async componentDidMount() {
  if (isClient) {
    await loginWithToken().then((user) => {
      console.log(user);
      if (user && user._id) {
        console.log("HERE");
        store.dispatch({
          type: "LOGIN",
          authenticated: user && !!user._id,
          user,
        });
      }
    });
  }

  this.setState({ loading: false });
}

Looks like application was making a bunch of wrong moves by not waiting for user object to return. This caused redirect malfunction for public pages and showing Login and Signup buttons in the navigation bar when you actually authorized.

Overall it's not a big issue when you are developing locally and user object returns within a fraction of a second, but on production server far away, this may cause annoying experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant