React JS Authentication перезагружает проблему, это можно исправить? - PullRequest
0 голосов
/ 01 мая 2019

У меня проблема, когда пользователь входит в систему (успешно), и он перенаправляет его из aws cognito на мою secondPage, он перезагружает firstPage до обновления состояния (2 секунды), затем перенаправляет на secondPage. Как я могу перенаправить пользователь на secondPage, не перенаправляя его на firstPage?

Я написал комментарий в коде, где может быть проблема.

class AuthRouter extends Component {
    constructor(props){
        super(props);
        this.state = {
            authenticated: this.props.authStore.isAuthenticated()
        };
    }

    handleAuthChange = authenticated => {
        this.setState({ authenticated: authenticated });
    };

componentWillMount() {
    this.props.authStore.subscribe(this.handleAuthChange);
};
componentWillUnmount() {
    this.props.authStore.unsubscribe();
};

render() {
    return (
        <div>
             /// The problem happens here, it checks the state, couple of seconds it updates to true then it redirects to secondPage, I need a delay until the state is updated... or how this can be changed.
            {!this.state.authenticated && (
                <Router component={firstPage}/>
            )}
            {this.state.authenticated && (
                <Router component={secondPage}/>
            )}    
        </div>
    );
}

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...