简体   繁体   中英

Uncaught TypeError: unknown stream type "undefined" when using React's 'activedirectory' module

I have this simple React component to handle Active Directory authentication:

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>
  }
}

When I attempt to use this component:

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

My App does not load and I get this error in the console:

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)

Any idea what needs to setup for bunyan to properly have a stream? This seems to me like an issue in the 'activedirectory' module, as I think it should properly create stream through bunyan. But I am not entirely sure, since I am very new to React.

Update (10/31/2018): the 'activedirectory' module works perfectly in Javascript. The issue above is only seen in React. I had to write a separate Javascript app to interact with activedirectory and use it from my React app. While this works as a workaround, it would be nice if the above issue is fixed so that all of the code is in React.

There's an open pull request on the activedirectory module on Github which addresses this issue: https://github.com/gheeres/node-activedirectory/pull/150/files

I tried it locally and it resolves the issue. Hopefully the PR will be merged eventually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM