Running a function once Meteor.user() is created

Hi there,
Can i run a function, once the Meteor.user() is created. I am using completely customized login with accounts UI. So want to customize scripts according to me. Is there any method , to run a function capturing any change in meteor.user()…? i am not aware how to use callbacks in this case.

Yes, you can

If you’re wanting to run a function every time Meteor.user() changes, you may want an autorun function:
(This is on the client.)

Tracker.autorun(function () {
  if (Meteor.user()) {
    // Do something

The function inside the Tracker.autorun will run once when the document for the current user first arrives on the client, then every time the Meteor.user() document changes, as Meteor.user() is a reactive data source.

Thanks a lot… this is exactly what i was lookin for.

I was doing it before with the help of helper function. i created a dummy helper on front end( Blaze ), and then run helper function inside that i put if(Meteor.user()) statement inside this. But i dont believe this to be a feasible solution. So thanks for providing this :blush: .

1 Like