bernabe9 / redux-react-session

:key: Simple Session API storage for Redux and React
https://bernabe9.github.io/redux-react-session/
147 stars 41 forks source link

Redux Thunk - instance.store.dispatch is not a function #15

Closed aeciolevy closed 6 years ago

aeciolevy commented 7 years ago

Hi,

I am using Redux Thunk and I am getting this message when I try to save the session. This is my action creator:

export function login(data, history){
  return async function(dispatch){
    const response = await post('/users/login', data);
    if (response.result){
      const {token} = response;
      sessionService.saveSession(token);
      history.push(`/user/${response.id}`);
    } else{
      console.log(response.message);
    }
  }
}

I also tried this.

export function login(data, history){
  return async function(dispatch){
    const response = await post('/users/login', data);
    if (response.result){
      const {token} = response;
      sessionService.saveSession(token)
      .then( () => {
      history.push(`/user/${response.id}`);
      });
    } else{
      console.log(response.message);
    }
  }
}

I could not figure out why.

bernabe9 commented 6 years ago

Hi @aeciolevy, sorry for the delay. I'm pretty sure that you are missing something of the usage instructions(https://github.com/bernabe9/redux-react-session#usage) You must add the session reducer and Initiate the session service.

Let me know if it works