bernabe9/redux-react-session

How to get user information of current session

goiPP opened this issue · 5 comments

goiPP commented

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?

  1. Did you follow the initialization steps https://github.com/bernabe9/redux-react-session#usage ?
  2. Did you save the session using sessionService.saveSession before trying to load it?
goiPP commented

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));
  }
}
goiPP commented

Thank you, it works now

@bernabe9 What about how to access logout function out of Home.js