【发布时间】:2018-01-13 02:58:12
【问题描述】:
使用 redux 在 react-native 应用程序中保存访问令牌的最佳做法是什么?
在 Redux 中,我曾经保存整个凭证,包括一些用户信息到状态:
//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
之后,我发现了一个新模块redux-persist,它可以帮助我将状态保存到设备存储中,localStorage。但是,商店中的所有内容都将被保存。使用 redux-persist 保存访问令牌是一种好习惯吗?
如果没有,我应该使用什么?
【问题讨论】:
标签: firebase react-native redux