reactjs-ts-identityserver icon indicating copy to clipboard operation
reactjs-ts-identityserver copied to clipboard

User is not properly persisted in redux store

Open dmoka opened this issue 4 years ago • 2 comments

Hey!

First of all, I would like so say thank you for your project! It helped me to lot to understand the concepts and I could successfully apply it in my projects! Keep it up!

I have found out something which worries me. If I run the whole app environment (specified in the README) and if I retrieve the store somewhere, I do not see the User properly persisted in the redux store. What I have just done is to log the redux state for example at UserInfo page.

import store from '../configureStore'
import {createHashHistory} from 'history';

console.log(store(createHashHistory()).getState())

Reproduction scenario:

  1. Log in IdentityServer
  2. Open UserInfo page
  3. As a log result, I got the following:
counter: {count: 0, isLoading: false}
router: {location: {…}, action: "POP"}
oidc: {user: null, isLoadingUser: false}
__proto__: Object

As you can see the user is null. Is it the expected behaviour?

Of course, if I generally connect a component to the redux store, and I retrieve the user data via props, it can be done successfully and I can read all the relevant data (access_token, etc). But let's say that we are at the UserInfo page showing all the data. If the access_token is refreshed (with a silentRenew) then the page is not rerendered. Is it the expected behaviour by you? I would expect a rerender, since the underlying User has got another access_token from the silentRenew.

Thank you very much for your help, I appreciate it!

Kind Regads, Daniel Moka

dmoka avatar Mar 17 '20 14:03 dmoka

Hi @mirind4, thanks for the feedback, I'm glad this project could help you :)

I don't quite understand the frst part of you question, if I follow your reproduction steps, the user is properly persisted to the store. You seem to be logging the store from App.tsx, this is called on intial load so the store will always be empty at that point. By the way, the store is already logged to the console with redux logger, so no need to add extra logs ;)

About the silent renew, you are right, the UserInfo page should be re-rendered, but it is not. I will have a look, and get back to you on that one.

ThunderDev1 avatar Mar 22 '20 11:03 ThunderDev1

Hey TunderDev1,

First of all many thanks for you answer! As for my reproduction scenario I have done it on the UserInfo page, and after I log in with an user, I checked it the logging coming from this

console.log(store(createHashHistory()).getState())

Then it produces the above mentioned result, where the user is null. If I connect to the store, I can see the user persisted, on the other hand, if I retrieve it with the command "store(createHashHistory()).getState()", I receive null for user. But right now I think I know where the problem can come from. Does it have something to do with the fact that I create a new store with hash history in the UserInfo page? What do you think?

As for the second issue, thanks again for checking it out, I look forward to you additional feedback! Keep it up the good work!

dmoka avatar Mar 22 '20 12:03 dmoka