iron-router waitOn Meteor.user()
Asked Answered
P

2

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?

Pliske answered 16/8, 2014 at 8:0 Comment(6)
Do you have Router.onBeforeAction('loading') anywhere? Without it, waitOn wont wait.Lumbering
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)Pliske
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().Matthews
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 :(Pliske
@Pliske Hmm that's mysterious.Matthews
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!! :(Pliske
B
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/

Bilow answered 6/10, 2014 at 18:53 Comment(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.Bilow
P
0

Only as workaround can be used:

if(this.ready())

in data function

Pliske answered 17/8, 2014 at 10:37 Comment(1)
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.Wight

© 2022 - 2024 — McMap. All rights reserved.