Accounts-base:Uncaught Error: options.password must be a string

Always get Uncaught Error: options.password must be a string when createUser with Accounts-base, console.log the type of password is also string.

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Accounts } from 'meteor/accounts-base';

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Accounts } from 'meteor/accounts-base';

class Register extends Component{
  constructor(props) {
     super(props);
     this.handleSubmit = this.handleSubmit.bind(this);
   }

  handleSubmit (event){
    event.preventDefault();
    const email= ReactDOM.findDOMNode(this.refs.email).value;
    const password = ReactDOM.findDOMNode(this.refs.password).value;
    const res = Accounts.createUser(email, password);
    console.log(res);
  }

  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <div className="form-group">
          <label htmlFor="email">Email:</label>
          <input className="form-control" type="email" ref="email"/>
        </div>
        <div className="form-group">
          <label htmlFor="password">Password:</label>
          <input className="form-control" type="password" ref="password"/>
        </div>
        <div className="form-group">
          <button type="submit" className="btn btn-primary">Submit</button>
        </div>
      </form>
    );
  }
}

export default Register;

This is the syntax:
Accounts.createUser(options, [callback])

The argument options needs to be an object that takes email and password.

const res = Accounts.createUser({
  email: email,
  password: password
});

and [callback] is an optional callback.

1 Like