I am trying to develop the login functionality in meteor, and I am using jade-handlebars and coffeescript.
My coffeescript page:
Template.navigation.events
"submit #login-form": (e, t) ->
e.preventDefault()
if Meteor.userId()
Meteor.logout()
else
# retrieve the input field values
email = t.find("#login-email").value
password = t.find("#login-password").value
# If validation passes, supply the appropriate fields to the
# Meteor.loginWithPassword() function.
Meteor.loginWithPassword email, password, (err) ->
if err
# throw new Meteor.Error(403, "Username must have at least 3 characters")
alert "login unsucess, Please check your email and password currectly"
console.log err
else
alert "sucess"
$('#login-style').toggleClass('hide');
console.log Meteor.userId()
Meteor.Router.to('/')
false
My jade file:
body
.container
{{> Header}}
{{#isolate}}{{renderPage}}{{/isolate}}
template(name="Header")
{{> navigation}}
template(name="navigation")
{{#if currentUser}}
{{> login}}
{{else}}
{{> loginout }}
{{/if}}
In Chrome it works fine, but in Firefox I have to refresh my page to see the login or logout button.
try returning false instead of e.preventDefault()
refer this answer as well. e.preventDefault(); behaviour not working in Firefox?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.