meteor-tracker

How to apply Tracker.autorun? Meteor.userId() undefined right after refreshing page

会有一股神秘感。 提交于 2019-12-08 07:04:43
问题 I have a restricted page using Meteor.userId() and roles: class AdminPage extends Component { render() { return ( <div> { Roles.userIsInRole(Meteor.userId(), 'admin') ? ( <Master_Layout renderCenter={<Article_Editor />}/> ) : browserHistory.push('/') } </div> ) } } This code redirects user to "/" after refresh because Meteor.userId() is undefined. How do I make sure Meteor.userId() is not undefined before rendering the page after refresh? I searched for answers. I found Tracker.autorun as a

How to apply Tracker.autorun? Meteor.userId() undefined right after refreshing page

我怕爱的太早我们不能终老 提交于 2019-12-06 16:41:40
I have a restricted page using Meteor.userId() and roles: class AdminPage extends Component { render() { return ( <div> { Roles.userIsInRole(Meteor.userId(), 'admin') ? ( <Master_Layout renderCenter={<Article_Editor />}/> ) : browserHistory.push('/') } </div> ) } } This code redirects user to "/" after refresh because Meteor.userId() is undefined. How do I make sure Meteor.userId() is not undefined before rendering the page after refresh? I searched for answers. I found Tracker.autorun as a solution, but I did not understand how to apply it. Thank you for help. I updated the code: constructor