# Load the State from the Session

**URL:** <https://discourse.sst.dev/t/load-the-state-from-the-session/157>\
**Category:** Chapter Comments\
**Created:** [May 9, 2018, 8:16pm UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157 "2018-05-09T20:16:17Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![Tonny](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/tonny/32/506_2.png) [@Tonny](https://discourse.sst.dev/u/Tonny)\
**Post date:** [August 30, 2019, 5:26am UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/21 "2019-08-30T05:26:42Z")

</div>

I have a problem, so far in the App.js the `this.state.isAuthenticated` is returning `true and is working as expected.

However, the `childProps` object sent to the Routes doesn’t seem to be updated because when I call `this.props.isAuthenticated` from the New.js or List.js file the value is `false`. Can you guys help me?

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [September 2, 2019, 4:10pm UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/22 "2019-09-02T16:10:32Z")

</div>

Hmm I think you might be a little confused about what the `isAuthenticating` and `isAuthenticated` flags are doing here. I’m not entirely sure what the concern here is but let me expand on what is being done.

The entire session is managed not by our app code but by the Cognito SDK. We need to use some React state to handle the checking process.

- When our app first loads, we don’t know if the user is logged in or not.
- So we want to hold off rendering the app. That’s the purpose of `isAuthenticating`. And it’s the reason why we don’t need to reset it after the user logs out.
- To check if the user is logged in we need to run `await Auth.currentSession()`. Once that check is done we set `isAuthenticated` is they are and set `isAuthenticating` to false to render our app.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [September 2, 2019, 4:11pm UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/23 "2019-09-02T16:11:07Z")

</div>

That’s really strange. Have you compared your code to the one in the repo?

> **[AnomalyInnovations/serverless-stack-demo-client](https://github.com/AnomalyInnovations/serverless-stack-demo-client)**
>
> Source for the demo app client in Serverless-Stack.com - AnomalyInnovations/serverless-stack-demo-client

---

<div class="post-metadata">

**Author:** ![ztc212](https://avatars.discourse-cdn.com/v4/letter/z/5e9695/32.png) [@ztc212](https://discourse.sst.dev/u/ztc212)\
**Post date:** [September 4, 2019, 2:26am UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/24 "2019-09-04T02:26:48Z")

</div>

Thanks Jay, this was really helpful! Just today I noticed a page that was rendering with no data and then refreshing with data immediately after. FWIW, it was a Lambda that called another AWS resource.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [September 8, 2019, 5:55pm UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/25 "2019-09-08T17:55:37Z")

</div>

Hmm what do you mean refreshing immediately after? Do you mean it was loading after a delay?

---

<div class="post-metadata">

**Author:** ![ztc212](https://avatars.discourse-cdn.com/v4/letter/z/5e9695/32.png) [@ztc212](https://discourse.sst.dev/u/ztc212)\
**Post date:** [September 19, 2019, 1:26am UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/26 "2019-09-19T01:26:51Z")

</div>

Thanks Jay, when I sent that message I had a good understanding of React’s downward rendering flow but I wasn’t thinking about Routes (using react-router) as “screens”. I was also experimenting with async methods and I had removed the isAuthenticating code (from my prior message). The combination of those led to a Route being rendered before the async data was returned and what I referred to as a “refreshing”. I don’t believe the whole DOM ever refreshed, just the part in the Route component…

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [September 28, 2019, 6:27pm UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/27 "2019-09-28T18:27:13Z")

</div>

I see. So whats the issue you are having now?

---

<div class="post-metadata">

**Author:** ![bgirr](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@bgirr](https://discourse.sst.dev/u/bgirr)\
**Post date:** [October 9, 2019, 2:14am UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/28 "2019-10-09T02:14:21Z")

</div>

Thanks a lot! That made my day!

---

<div class="post-metadata">

**Author:** ![yveshema](https://avatars.discourse-cdn.com/v4/letter/y/a88e4f/32.png) [@yveshema](https://discourse.sst.dev/u/yveshema)\
**Post date:** [April 13, 2020, 9:31pm UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/29 "2020-04-13T21:31:33Z")

</div>

# Show only the login and signup pages when user not logged in

First let me just say how much I have enjoyed this guide. Honestly, it’s the best tutorial I have ever come across, period.  
With regard to login session handling, I noticed that when the user logged out, they are redirected to the login page, however, if you manually enter the home page path in the browser, the home page still shows. I am not sure if this is the desired effect.  
I tried to add a redirect within the catch block of the onLoad function after error handling, but this had no effect when the user clicks on the home link.  
I was wondering if there was a way to make the Login page the default for non-logged in users even when they manually navigate to a different route.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [April 25, 2020, 4:38pm UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/30 "2020-04-25T16:38:19Z")

</div>

Thanks for the kind words.

Right now the home page is not an authenticated route, you’ll need to switch it over. That’ll make it redirect to the login page as well.

> <https://github.com/AnomalyInnovations/serverless-stack-demo-client/blob/master/src/Routes.js#L18>

---

<div class="post-metadata">

**Author:** ![JakeMetz8](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@JakeMetz8](https://discourse.sst.dev/u/JakeMetz8)\
**Post date:** [April 28, 2020, 12:21pm UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/31 "2020-04-28T12:21:39Z")

</div>

I believe I am running into this same issue as I created my user in the AWS console. The account status is FORCE\_CHANGE\_PASSWORD . However, when I try to run the CLI command provided it fails and states:

`You must specify a region. You can also configure your region by running "aws configure".`

Fundamentally, I’m not understanding the root issue.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 3, 2020, 1:06am UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/32 "2020-05-03T01:06:59Z")

</div>

I think your AWS CLI needs a default region set.

---

<div class="post-metadata">

**Author:** ![Akash76](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/akash76/32/1112_2.png) [@Akash76](https://discourse.sst.dev/u/Akash76)\
**Post date:** [January 21, 2021, 5:56am UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/33 "2021-01-21T05:56:04Z")

</div>

I have followed the tutorial as it was mentioned… But I am not able to upload a file to S3 bucket. “AWSS3Provider - ensure credentials error cannot get guest credentials when mandatory signin enabled” This is the error. Kindly please help me!

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 15, 2021, 8:30pm UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/34 "2021-05-15T20:30:13Z")

</div>

It looks like the user isn’t logged in? At which step are you seeing this?

---

<div class="post-metadata">

**Author:** ![Sparky](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Sparky](https://discourse.sst.dev/u/Sparky)\
**Post date:** [July 23, 2021, 4:41am UTC](https://discourse.sst.dev/t/load-the-state-from-the-session/157/35 "2021-07-23T04:41:56Z")

</div>

Hello guys,  
Can anyone help me out here, I am new with react.  
So the issue I am having is I have an extra field in my db that takes care of user type so like user, employee or admin. I am creating a dynamic nav so it will be different for each type of user I have tried using context but when the page is refreshed it is getting reinitialized with the default value. Do you know any way to do it. It will be great help!  
P.S. I want a secure way that can’t be seen on browser or can be edited by user so I came across local storage but its not secure.

[Previous page](https://discourse.sst.dev/t/load-the-state-from-the-session/157.md?page=1)
