10

I would use Meteor.user() in data iron-router, but this is undefined at start...

I'm trying with:

waitOn: function() {
   return curretUserHandle;
},
data: function() {
   // access to Meteor.user().username, give me undefined

[...]

var curretUserHandle = {
    ready: function () {
        return 'undefined' !== typeof Meteor.user();
    }
};

but data function of route is always call before curretUserHandle.ready() return true

I know that i can add if(Meteor.user()) in data, but this option don't like.

Why data don't wait that Meteor.user() is ready?

elbowz
  • 557
  • 1
  • 4
  • 19
  • Do you have `Router.onBeforeAction('loading')` anywhere? Without it, `waitOn` wont wait. – Peppe L-G Aug 16 '14 at 08:07
  • Yes @PeppeL-G, I have: `loadingTemplate: 'Loading'` and `Router.onBeforeAction('loading');`... The problem occur only when user go directly to the route or refresh page (F5) – elbowz Aug 16 '14 at 09:17
  • I am curious why you're complicating the hadle so much. I am pretty much sure that all you need is just `return !!Meteor.user()`. – Tomasz Lenarcik Aug 16 '14 at 10:14
  • ehehe... you have right @apendua. I have done a copy&paste from another place and I don't taken care to the code...but the problem remain :( – elbowz Aug 16 '14 at 10:32
  • @elbowz Hmm that's mysterious. – Tomasz Lenarcik Aug 16 '14 at 11:55
  • thanks anyway @apendua! ..btw, I think the correct handle should be `'undefined' !== typeof Meteor.user()`. return `true` also if no user is logged...but the problem is that `data` don't want wait!! :( – elbowz Aug 16 '14 at 12:17

2 Answers2

1

Adding https://atmospherejs.com/meteorhacks/fast-render 'magically' solves this.

However, please read the note on necessary security measures: https://meteorhacks.com/fast-render/security-measures/

workflow
  • 2,536
  • 2
  • 14
  • 11
  • 1
    I believe it only solves the race condition between the iron-router initialization code running on first page refresh and the check for user login data. Other reactive variables worked fine for me with waitOn. – workflow Oct 08 '14 at 12:38
0

Only as workaround can be used:

if(this.ready())

in data function

elbowz
  • 557
  • 1
  • 4
  • 19
  • I've a situation where this.ready() returns true without the data being subscribed. After checking the in console, the data is nowhere. iron:router has too many magical problems. – Mário Oct 10 '14 at 17:00