I've recently picked up MeteorJs and really dig it. I've gotten 99% of my app to work, except for this one nagging bug (I've been chasing it for two days now).
The issue is logging in, or more appropriately, what happens after a user signs in, or when a user creates an account. My code below works, but it appears to be a timing issue of sorts.
If I take out the containing call to Deps.autorun
, sign in fails as it doesn't find a room. BUT, if then creating an account fails as it doesn't have a user profile. Note that even when it fails, I can refresh the page and everything works. I've stepped through the code a hundred times and this has to be it.
Anything glaringly obvious?
Deps.autorun ->
if Meteor.user()
user = Meteor.user()
userId = Meteor.userId()
email = user.emails[0].address
Meteor.subscribe "rooms", email
if user.profile is undefined
if Rooms.findOne() is undefined
roomId = Rooms.insert({name: "Watercooler", ownerId: userId, inviteeEmails: [], roster: []})
else
roomId = Rooms.findOne()._id
Meteor.users.update({_id: userId}, {$set:{'profile.lastRoomId': roomId, 'profile.showGravatars': true}})
else
roomId = user.profile.lastRoomId
Meteor.subscribe "connections"
Meteor.subscribe "messages", roomId
Meteor.subscribe "last_in_room", roomId
Meteor.call 'addUserToRoster', roomId
Meteor.setInterval ->
Meteor.call 'keepalive', userId
, 5000
if(Meteor.user()){if(Meteor.user.profile){if(Meteor.user.profile.lastRoomId){//do stuff}}}
--
You received this message because you are subscribed to a topic in the Google Groups "meteor-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/meteor-talk/8lKB47kSSgY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
The longer answer involves:- Using Meteor.autorun() instead of Deps.autorun()
--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.