小编man*_*eer的帖子

我应该用redis存储JWT令牌吗?

我正在用ExpressJS,Mongodb(Mogoose)构建一个应用程序.应用程序包含用户在访问之前必须进行身份验证的路由.

目前我已经编写了一个快速中间件来做同样的事情.在JWT令牌的帮助下,我正在进行mongodb查询以检查用户是否经过身份验证.但是觉得这可能会对我的数据库加载不必要的请求.

我应该将redis集成到这个特定的任务中吗?
它会改善API性能吗?还是应该继续使用现有的mongodb方法?

如果我对此有更深入的了解,将会有所帮助.

mongodb redis node.js express jwt

14
推荐指数
2
解决办法
1万
查看次数

主持人:localhost.不在cert的altnames中

我在服务器端渲染时遇到错误.

RENDERING ERROR: { [Error: Network error: request to https://api-dev.xyz.io/graphql failed, reason: Hostname/IP doesn't match certificate's altnames: "Host: localhost. is not in the cert's altnames: DNS:*.xyz.io"]
  graphQLErrors: null,
  networkError: 
   { [FetchError: request to https://api-dev.xyz.io/graphql failed, reason: Hostname/IP doesn't match certificate's altnames: "Host: localhost. is not in the cert's altnames: DNS:*.xyz.io"]
     name: 'FetchError',
     message: 'request to https://api-dev.xyz.io/graphql failed, reason: Hostname/IP doesn\'t match certificate\'s altnames: "Host: localhost. is not in the cert\'s altnames: DNS:*.xyz.io"',
     type: 'system',
     errno: undefined,
     code: undefined },
  message: …
Run Code Online (Sandbox Code Playgroud)

ssl-certificate node.js reactjs graphql react-apollo

8
推荐指数
1
解决办法
2547
查看次数

React-UseState-为什么setTimeout函数没有最新状态值?

最近我正在研究React Hooks,陷入一个问题/疑问?

下面是重现此问题的基本实现,在这里,我只是flag在单击按钮时切换(状态)变量。

  const [flag, toggleFlag] = useState(false);
  const data = useRef(null);
  data.current = flag;

  const _onClick = () => {
    toggleFlag(!flag);
    // toggleFlag(!data.current); // working

    setTimeout(() => {
      toggleFlag(!flag); // does not have latest value, why ?
      // toggleFlag(!data.current); // working
    }, 2000);
  };

  return (
    <div className="App">
      <button onClick={_onClick}>{flag ? "true" : "false"}</button>
    </div>
  );
Run Code Online (Sandbox Code Playgroud)

我想出了一些其他方法来克服此问题,例如使用useRef或useReducer,但这是正确的吗?或者是否有其他方法只能通过useState解决此问题?

另外,如果有人解释为什么我们在setTimeout中获得旧的state值这将非常有帮助

沙盒网址-https: //codesandbox.io/s/xp540ynomo

javascript reactjs react-hooks

5
推荐指数
2
解决办法
794
查看次数

使用setRouteLeaveHook(withRouter)时出现错误

目前,我正在使用ReactJS构建一个Web应用程序。该应用程序具有注册表。

现在考虑,用户已开始注册过程。但是在提交表单之前,用户离开了此注册页面。此时,说表单包含未保存的数据,我想显示一条确认消息,说您在离开此屏幕之前已保存了更改

下面是我实现此目的的代码

  componentDidMount () {
    this.props.router.setRouteLeaveHook('/enterprise/enterprise-area/enterprise-details', this.routerWillLeave);
  }

  routerWillLeave(nextLocation) {
    // return false to prevent a transition w/o prompting the user,
    // or return a string to allow the user to decide:
    if (true) {
      return 'Your work is not saved! Are you sure you want to leave?';
    }
  }

export default withRouter(connect(
  mapStateToProps,{
  initializeVendorDetails
})(VendorRegistration));
Run Code Online (Sandbox Code Playgroud)

我收到如下所示的错误:

Uncaught TypeError: Cannot assign to read only property '__id__' of /enterprise/enterprise-area/enterprise-details
Run Code Online (Sandbox Code Playgroud)

我浏览了官方文档和github问题,但一无所获。谢谢您的期待。

reactjs react-router

0
推荐指数
1
解决办法
2639
查看次数