meteorite - How to display Meteor.loginWithPassword callbak error message on the same page -


I created a custom login page and used Meteor.loginWithPassword (user, password, [callback]) function to login in the app.

The login template is the following:

  & lt; Template name = "Login" & gt; & Lt; Form class = "login-form form-horizontal" & gt; & Lt; Div class = "control-group" & gt; & Lt; Input class = "email" type = "text" placeholder = "email" & gt; & Lt; / Div & gt; & Lt; Div class = "control-group m-inputwrapper" & gt; & Lt; Input class = "password" type = "password" placeholder = "password" & gt; & Lt; / Div & gt; & Lt; Div class = "control-group" & gt; & Lt; Button type = "submit" class = "submit t-btn-login" & gt; Login & lt; / Button & gt; & Lt; / Div & gt; & Lt; / Form & gt; & Lt; Div class = "alert-container" & gt; & Lt; Div class = "alert-placeholder" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Template & gt; Template.Login.events ({'Submit .login-form': function (e, t) {e.preventDefault (); // input field values ​​var email = t.find ('. Email') Value, password = t.find ('.password'). Value; Meteor.loginWithPassword (email, password, function (error) {$ (".path-placeholder"). Html ('& lt ; div> 
"icon-icon"> & gt; '+ err.message +' & lt; / span & gt; & lt; / div & gt;; ')}}}; Details are false;}});

As I debugging, I can see that an error message is displayed and added to the Dome. But it will be refreshing and the message will disappear.

Meteor.loginWithPassword () is the meteor after the page mentioned again? When using meteor, if you find yourself injecting HTML elements with jQuery, how can you remove it?

In your alert container, conditionally an error message:

  & lt; Div class = "alert-container" & gt; {{#if error message}} & lt; Div class = "alert" & gt; & Lt; Span & gt; & Lt; I class = "icon-mark" & gt; & Lt; / I & gt; {{Error message}} & lt; / Span & gt; & Lt; / Div & gt; {{/ If}} & lt; / Div & gt;   

In your login callback, set error message if err exists:

  Meteor.loginWithPassword (email, password, function (error) {if (err) {session .set ('errorMessage', err.message);}});   

Finally, add a template assistant to use the error message session variable:

  Template.Login.helpers ({errorMessage: function () {return Session.get ('errorMessage');}});    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -