How to detect if user has just logged in or has just logged out?

4,395 views
Skip to first unread message

Len

unread,
Apr 4, 2014, 11:49:08 PM4/4/14
to meteo...@googlegroups.com
I tried googling but I couldn't find the answer.

Chanpory Rith

unread,
Apr 5, 2014, 12:18:26 AM4/5/14
to meteo...@googlegroups.com
If you're looking to register a callback when a user logs in you can use Accounts.onLogin():


Not sure where there isn't Accounts.onLogout, but you can add a callback with Meteor.logout(). 





On Fri, Apr 4, 2014 at 11:49 PM, Len <lleon...@gmail.com> wrote:
I tried googling but I couldn't find the answer.

--
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.
For more options, visit https://groups.google.com/d/optout.

Gabriel Pugliese

unread,
Apr 5, 2014, 12:24:30 AM4/5/14
to meteo...@googlegroups.com
Careful because Accounts.onLogin is called only on server.
If you want to know when a user is logged in on client, you just do:
Deps.autorun(function () {
  if (Meteor.user()) console.log('User is logged');
  else console.log('User is not logged');
});



Gabriel Pugliese
CodersTV.com
@coderstv

Len

unread,
Apr 6, 2014, 5:35:47 PM4/6/14
to meteo...@googlegroups.com
Deps.autorun seems like the way to go, but I'm using Iron-Router and I'd like to redirect but Router.go doesn't seem to work inside deps.autorun.

Gabriel Pugliese

unread,
Apr 6, 2014, 6:04:12 PM4/6/14
to meteo...@googlegroups.com
Yes, it does. Can you post the code?



Gabriel Pugliese
CodersTV.com
@coderstv

Len

unread,
Apr 6, 2014, 6:38:16 PM4/6/14
to meteo...@googlegroups.com

Andrew Mao

unread,
Apr 7, 2014, 11:42:31 AM4/7/14
to meteo...@googlegroups.com
On the server side, you probably want to use https://github.com/mizzao/meteor-user-status

Gwendall Esnault

unread,
Nov 13, 2014, 3:58:33 AM11/13/14
to meteo...@googlegroups.com
Should you need client-side callbacks, I just published this package:
Reply all
Reply to author
Forward
0 new messages