如何解决我们可以用Cookie代替本地存储以在基于NGRX的身份验证中存储令牌吗?
Auth Module.ts
我想用cookie替换本地存储,可以吗?
import { localStorageSync } from 'ngrx-store-localstorage';
const localStorageRules = {
keys: [
{ auth: { deserialize: AuthState.deserialize } }
],rehydrate: true,storage: sessionStorage
};
export function localStorageSyncWrapper(reducer: any) {
return localStorageSync(localStorageRules)(reducer);
}
解决方法
您可以安装let array = [{
"19714": false,"19787": true,"19870": false,},{
"19716": false,"19797": true,"19890": true,"19891": true,"19892": true,"19894": true,{
"16789": false,"19370": true,"19470": true,"19785": false,"19800": true
}
];
array.forEach(a => {
let trueValues = Object.entries(a).filter(e => e[1] === true);
let falseValues = Object.entries(a).filter(e => e[1] === false);
if (trueValues.length == 1) {
a[trueValues[0][0]] = false;
} else if (falseValues.length == 1) {
a[falseValues[0][0]] = true;
}
});
console.log(array);
来存储或删除Cookie。
有关npm pakage ngx-cookie-service
的更多信息版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。