Uncaught Error: options.password must be a string

When I tried to register an account on the localhost, I get the uncaught error: options.password must be a string on meteorJS. I’ve already added the accounts-password package. Does anyone know how to solve it? Thanks!

<form class="register">
    <input type="email" placeholder="Email" class="input"><br>
    <input type="password" placeholder="Choose a password" class="input"><br>
    <input type="submit" value="Create Account" class="btn"><br>
</form>
Template.register.events({
    'submit form': function(event){
        event.preventDefault();
        var email = $('[name=email]').val();
        var password = $('[name=password]').val();
        Accounts.createUser({
            email: email,
            password: password
        });
    }
});

Welcome @tiffanyyyy!

The above code looks for an element where the name equals password. The password field does not have a name attribute:

<input type="password" placeholder="Choose a password" class="input">

Actually, neither does the email field.

To solve this issue, add the name attributes to the input elements:

<form class="register">
    <input name="email" type="email" placeholder="Email" class="input"><br>
    <input name="password" type="password" placeholder="Choose a password" class="input"><br>
    <input type="submit" value="Create Account" class="btn"><br>
</form>

It’s also recommended in Blaze forms to scope jquery selectors to your template like so:

Template.register.events({
    'submit form': function(event, instance){
        event.preventDefault();
        var email = instance.$('[name=email]').val();
        var password = instance.$('[name=password]').val();
        Accounts.createUser({
            email: email,
            password: password
        });
    }
});

Note the second argument to a handler in Blaze — the template instance — which is then used when selecting the inputs instance.$(selector)

1 Like