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

onEnter problem of use #3016

Closed
IronTony opened this issue Apr 26, 2018 · 2 comments
Closed

onEnter problem of use #3016

IronTony opened this issue Apr 26, 2018 · 2 comments

Comments

@IronTony
Copy link

IronTony commented Apr 26, 2018

Hi,

I don't know if I am against any repo rule, I hope not so I try anyway.
I am trying to use the onEnter property in the Scene. What I am trying to do is to check if an user is authenticated per Scene, if not redirect to Login page.

I am doing something like this, in the App.js component:

class App ..... {
    isLogged(isAuth) {
        if (isAuth) {
            Actions.Login();
        }
     };

     render() {
         .......
         return (
             <Provider store={store}>
             <PersistGate loading={null} persistor={persistor}>
             <Router>
                 <Scene key="root">
                     <Scene
                         key="Login"
                         component={Login}
                         gesturesEnabled={false}
                         hideNavBar
                      />
                     <Scene
                         key="Home"
                         component={Home}
                         gesturesEnabled={false}
                         hideNavBar
                         onEnter={this.isLogged(isAuth)}
                      />
                </Scene>
         </Router>
         </PersistGate>
         </Provider>
      );
    }
}

Unfortunately when I execute this code, I get back this error:
TypeError: _reactNativeRouterFlux.Actions.Login is not a function

Any help on this would be more than welcome.

Version

  • react-native-router-flux v4.0.0-beta.28
  • react-native v0.55.2
@ryanmr
Copy link

ryanmr commented Apr 30, 2018

I don't know if this will solve your problem. onEnter needs a function reference, while you gave it this.isLogged(isAuth) which resolves to undefined (which is not a function).

Try this: onEnter={() => this.isLogged(isAuth)}. Note, it is unclear what isAuth is or if it's even in scope.

@IronTony
Copy link
Author

IronTony commented May 2, 2018

@ryanmr Thank you for the answer. It was my fault in the upper code.
The only problem I get now is that the isAuth prop (is a value that I set in the store/persist) is not received as true when moving from Login to Home when I log in.

@aksonov aksonov closed this as completed Jun 6, 2018
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

3 participants