【发布时间】:2020-06-20 20:49:39
【问题描述】:
我一直在自学 Redux,想知道在 Redux 状态下存储 JWT 令牌有多安全。
例如,这里有一个reducer,它负责设置和重置一个token。
export default function loginReducer(state = {
token: "",
}, action) {
switch (action.type) {
case "SET_TOKEN":
{
return {
...state,
token: action.data,
}
break;
}
//other cases here
return state
}
然后,您可以通过以下方式存储令牌。
handleSubmit(values) {
//Calling an API to get a token.
}).then((response) => {
response.json().then((jsonReponse) => {
//This is where the token is stored!
this.props.dispatch(loginAction.setToken(jsonReponse.token));
});
});
}
使用 Redux 的主要目的是将状态组织在一个地方,所以我认为在那里维护令牌是合理的。
但是,我还没有找到一个很好的信息资源来解释这样做的安全性/脆弱性。
(我发现了几篇关于 localStorage 与 Cookies 的帖子。Apparently Cookies would be a secure place for storing tokens, as far as I've researched)
任何建议将不胜感激!
【问题讨论】: