How to get user information of current session
goiPP opened this issue · 5 comments
import {sessionService} from 'redux-react-session'; class AboutUs extends Component { render() { sessionService.loadSession() .then(currentSession => console.log(currentSession)) .catch(err => console.log(err))
this printed out 'undefine', please give me some advice
Hi, can you give a little bit more of context?
- Did you follow the initialization steps https://github.com/bernabe9/redux-react-session#usage ?
- Did you save the session using
sessionService.saveSession
before trying to load it?
I use your example code and it shows correct result in Home.js . I just want to get user information in another page. Can i use loadUser() or use mapSate() as Home.js
Both ways should work..
I recommend to use the mapState
approach but if you want to access directly to the data in the storage using loadUser
or loadSesion
is fine.
I tried this in the Home.js
and it works great:
class Home extends Component {
componentWillMount() {
sessionService.loadSession().then(session => console.log(session));
sessionService.loadUser().then(user => console.log(user));
}
}
Thank you, it works now