content: import React from 'react';
  import auth from '../utils/auth.js';
  
  const Login = React.createClass({
  
    contextTypes: {
      router: React.PropTypes.object
    },
  
    getInitialState() {
      return {
        error: false
      }
    },
  
    handleSubmit(event) {
      event.preventDefault();
  
      const username = this.refs.username.value;
      const pass = this.refs.pass.value;
  
      auth.login(username, pass, (loggedIn) => {
        if (!loggedIn)
          return this.setState({ error: true });
  
        const { location } = this.props;
  
        if (location.state && location.state.nextPathname) {
          this.context.router.replace(location.state.nextPathname);
        } else {
          this.context.router.replace('/');
        }
      })
    },
  
    render() {
      return (
        <form onSubmit={this.handleSubmit}>
          <label><input ref="username" placeholder="username" /></label><br />
          <label><input ref="pass" placeholder="password" /></label><br />
          <button type="submit">login</button>
          {this.state.error && (
            <p>Bad login information</p>
          )}
        </form>
      );
    }
  });
  
  export default Login;
  