Closed Kyii closed 5 years ago
Hi @Kyii ,
Thank you. Glad it helps.
As Context providers are declared in Root you won't be able to use context consumer if you are not in inside provider.
But handling authentication is easily done:
You cannot access a context if you are not inside its provider. So as I use Root just to declare root components logic should be inside Root's children. Consumer could be used in Root jsx by rendering a function (like that) but you will loose the ability to access context in lifecycle so I dislike this way to use contexts.
@MacKentoch Hi, thank you so much for pointing me in the right direction. Your approach is working very well.
hey MacKentoch,
first of all thanks for putting together this great starter. i learned a lot about HOC and other more advanced stuff form your repo.
I am trying to enhance authentication a bit and maybe you could give me a little hint how you would approach this.
I want to avoid that authenticated users can access certain routes like login. Instead they should be redirected to dashboard. But i can't access props from
AuthProvider
inRoot.js
. So i tried (inRoot.js
):<Route exact path="/login" render={() => auth.isAuthenticated() ? ( <Redirect to="/dashboard" /> ) : ( <LoadableLogin /> ) } />
but this killed theRouterHistory
withinLogin.js
?Root.js
but still i can't get access to the necessary userInfo there.Am i missing something about how to access contextAPI props in
Root.js
?Thanks for your time! Greetings Kyii