简体   繁体   English

如何在 React.js 中定义 SecureLS 以保护 session 详细信息,例如 JWT 令牌?

[英]How to define SecureLS in React.js to secure session details like JWT token?

I have gone through the git for SecureLS, but I find it difficult to define SecureLS in React.我已经浏览了 SecureLS 的 git,但我发现很难在 React 中定义 SecureLS。

var ls = new SecureLS({ encodingType: 'aes' })

How can I define like this in React.js class component?如何在 React.js class 组件中这样定义?

With React class components, you can create instances of class within componentDidMount method in class components and store it in class variable使用 React class 组件,您可以在 class 组件的componentDidMount方法中创建 class 的实例并将其存储在 ZA2F2ED4F8EBC04ABCBDC4 变量中

class App extends React.Component {
  componentDidMount() {
     this.ls = new SecureLS({ encodingType: 'aes' })
  }

}

Now you can use ls anywhere in your class with this.ls现在您可以通过 this.ls 在this.ls的任何地方使用ls

PS Do keep in mind context issues whenever you use this.ls in class functions. PS在 class 函数中使用this.ls时,请记住上下文问题。 The this inside class functions must refer to the class instance class函数里面的this必须引用class实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React.js 如何从 jwt 令牌获取用户角色 - React.js how to get user roles from jwt token 在 React.js 项目中,如何在 jwt 令牌过期之前请求刷新令牌 api - How can I request refresh token api before jwt token expires in React.js project JWT 令牌与 Session 令牌用于 React Native 和 React Js - JWT TOken vs Session TOken for React Native And react Js 我无法在 react.js 的标头中发送 JWT 令牌 - I am not able to send JWT token in headers in react.js 如何从我的 react.js 前端的后端(Java Spring Boot)检索 JWT 令牌? - How to retrieve JWT token from back-end (Java Spring Boot) in my react.js front-end? 如何将认证系统与 spring 引导 jwt 连接到 React.js - How to connect authentication system with spring boot jwt to React.js 如何在react js中生成JWT令牌 - How to generate JWT token in react js React.js 最佳实践(最安全)基于角色的用户身份验证(JWT)和组件更新 - React.js Best Practice (Most Secure) Role-Based User Authentication (JWT) & Component Updating 如何在 React 应用程序中存储和保护我的 JWT 令牌 - How can I store and secure my JWT token in react application 如何在 React.js 应用程序中刷新 JWT 令牌? - How to refresh JWT tokens in React.js Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM