Michael
Michael

Reputation: 127

Meteor how to log in with the account-password package

I want to make a user login form. My registration form already works and with meteortoys i proved that everything it should be but now I am hanging on the login part.

This is my simple html:

<template name="Login">
    <form class="login" >
            <input type="email" name="Email" placeholder="E-Mail" />
            <input type="text" name="Passwort" placeholder="Passwort" />
            <input type="submit" value="Bestätigen" />
        </form>
</template>

and the javascript I got from https://www.sitepoint.com/creating-custom-login-registration-form-with-meteor/

Template.Login.events({
    'submit .login': function(event){
        event.preventDefault();
        var emailVar = event.target.Email.value;
        var passwordVar = event.target.Passwort.value;
        Meteor.loginWithPassword(emailVar, passwordVar);
        FlowRouter.go('/meineEvents');

        return false;
    }
});

I hope you can help me so I can fix the code thank you guys ;)

Upvotes: 0

Views: 30

Answers (1)

Michel Floyd
Michel Floyd

Reputation: 20226

Normally you would reroute in the callback from loginWithPassword and also deal with login errors:

Template.Login.events({
  'submit .login'(event) =>{
    event.preventDefault();
    const emailVar = event.target.Email.value;
    const passwordVar = event.target.Passwort.value;
    Meteor.loginWithPassword(emailVar, passwordVar,err=> {
      if ( err ) {
        console.log(err);
        // show alerts/warnings/Achtung!
      } else {
        FlowRouter.go('/meineEvents');
      }
    })
  }
});

Upvotes: 1

Related Questions