What is the best practice to save access token in react-native app with redux?

Viewed 1516

What is the best practice to save access token in react-native app with redux?

In Redux, I used to save the whole credential, including some user information to the state:

//Actions
export const successfulLogin = (firebaseAuth) => ({
    type: 'LOGIN_SUCCESSFUL',
    firebaseAuth
});

//Reducer
const authentication = (state = {}, action) => {
    switch (action.type) {
        case 'LOGIN_SUCCESSFUL':
            return {
                ...state,
                firebaseAuth: action.firebaseAuth
            };
        default:
            return state;
    }
}
export default authentication

After that, I found a new module redux-persist, which helps me to save the state to device storage, localStorage. However, everything in the store will be saved. Is it a good practice to save access token with redux-persist?

If not, what should I use?

2 Answers

It's been a while since this question was asked but with redux-persist you don't need to save the entire store. You can provide keys that you want to store and it will ignore keys that you have not specified.

Related