I am creating a library for my responsive application that will handle all the API calls associated with the session (authenticate, register, update tokens, etc.), and this library will have to access the reducer store on its own to send actions. The reason for this is in that whenever a user access token expires using setTimeout, I need to call the creator of the action, which will call my API to update the token, and update the application reduction storage with new session data.
So, I was thinking of passing the send method to the library whenever I call it the first time, but I'm not sure if this is the best way to do this.
Or I could also create a method initialize()that will pass the send to the library.
import { authenticate } from 'libraries/session';
export function login(email, password) {
return (dispatch) => {
dispatch(loginRequest());
return authenticate(email, password, dispatch)
.then(() => (
dispatch(loginSuccess())
))
.catch((json) => (
dispatch(loginError());
));
};
};
I have not tried this code yet, it is rather a brainstorm.
Do you have any suggestions on the best way to handle this?
Thank!
source
share