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

User loaded asyncroniously in browser #30

Closed
apedyashev opened this issue Apr 4, 2016 · 1 comment
Closed

User loaded asyncroniously in browser #30

apedyashev opened this issue Apr 4, 2016 · 1 comment

Comments

@apedyashev
Copy link

My application works with 3rd party API only so I'm going to serve files statically (and I.m unable to initialize the store on the server).
Because of that my app is always redirected to /login before user is loaded and added to the store.

It would be nice to have example or recommendations how to handle this case.

I have following workaround, but I don't like it:

const UserIsAuthenticated = UserAuthWrapper({
  authSelector: state => {
    return {
      wasRequested: state.isLoggedUserRequested,
      data: state.entities.loggedUser
    };
  },
  redirectAction: (path) => replaceState(null, path.pathname, path.query),
  wrapperDisplayName: 'UserIsAuthenticated',
  allowRedirectBack: false,
  predicate: user => {
    // logged user has not been requested yet - redirect to /login page is not required
    if (!user.wasRequested) {
      return true;
    }
    // user has been requested but user is not logged - redirect to /signin
    else if (user.wasRequested && isEmpty(user.data)) {
      return false;
    }

    return true;
  }
});

isLoggedUserRequested is set to true when request to /users/me has been completed.

@mjrussell
Copy link
Owner

@apedyashev thanks for the issue. I think its somewhat related to the discussions in #10 (comment). I think one solution would be to have an isAuthenticating/isLoggingIn selector and an optional component to display while this is true. If false, the normal auth flow kicks in.

Do you think that would solve this use case?

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

No branches or pull requests

2 participants