首页 > 解决方案 > 未捕获的 TypeError:使用 React 的“activedirectory”模块时的未知流类型“未定义”

问题描述

我有这个简单的 React 组件来处理 Active Directory 身份验证:

import React from 'react';
import ActiveDirectory from 'activedirectory';

export default class ActiveDirectoryComponent extends React.Component {
  state = {
    authResponse: undefined
  };

  componentDidMount() {
    var config = {
      url: 'ldap://compandomain.com:389',
      baseDN: 'dc=domainname,dc=com',
      username: 'user',
      password: 'pass'
    };

    var ad = new ActiveDirectory(config);
    var username = 'john.smith@domain.com';
    var password = 'password';

    ad.authenticate(username, password, function (err, auth) {
      if (err) {
        this.setState({ authResponse: { error: JSON.stringify(err) } });
        return;
      }

      if (auth) {
        this.setState({ authResponse: auth });
      } else {
        console.log('Authentication failed!');
        this.setState({ authResponse: { authFailed: true } });
      }
    });
  }

  render() {
    if (!this.state.authResponse) {
      return <div>Authenticating....</div>;
    }
    if (this.state.authResponse.error) {
      return <div>{this.state.authResponse.error}</div>
    }
    if (this.state.authResponse.authFailed) {
      return <div>Authentication Failed</div>
    }
    return <div>.....</div>
  }
}

当我尝试使用此组件时:

 import ActiveDirectoryComponent from '../components/ActiveDirectoryAuthentication'; 

我的应用程序未加载,我在控制台中收到此错误:

Uncaught TypeError: unknown stream type "undefined"
    at Logger.addStream (bunyan.js?a10b:620)
    at eval (bunyan.js?a10b:470)
    at Array.forEach (<anonymous>)
    at new Logger (bunyan.js?a10b:469)
    at Function.createLogger (bunyan.js?a10b:1618)
    at Object.eval (activedirectory.js?f995:16)
    at eval (990:1836)
    at Object.<anonymous> (bundle.js:1)
    at e (bundle.js:1)
    at eval (index.js?048a:1)

知道需要设置什么才能让 bunyan 正确拥有流吗?在我看来,这似乎是“activedirectory”模块中的一个问题,因为我认为它应该通过 bunyan 正确创建流。但我并不完全确定,因为我对 React 还很陌生。

更新(2018 年 10 月 31 日):“activedirectory”模块在 Javascript 中完美运行。上述问题仅在 React 中可见。我必须编写一个单独的 Javascript 应用程序来与 activedirectory 交互并从我的 React 应用程序中使用它。虽然这是一种解决方法,但如果上述问题得到修复,所有代码都在 React 中,那就太好了。

标签: reactjsreact-nativeactive-directory

解决方案


Github 上的 activedirectory 模块有一个开放的拉取请求,它解决了这个问题:https ://github.com/gheeres/node-activedirectory/pull/150/files

我在本地尝试过,它解决了这个问题。希望 PR 最终会合并。


推荐阅读