DEV Community

Đỗ Công Bằng
Đỗ Công Bằng

Posted on

Answer: REACT - Check authentication before render APP

The problem is that initial value of isLoggedIn is falsey, which triggers the redirect (before the state is updated asynchronously):

isLoggedIn ? (<Comp {...props} />) : (<Redirect to="/" />)

What you need is 3 states for 'loading', 'login succes' and 'login fail'.

Example with 2 boolean variables:

state = {

Top comments (0)