I am using accounts-password@1.4.0
package in my Meteor angular project.
Meteor.user()
method returns the current user details but when I refresh the page it returns undefined
. So is there any way we can remove this error? Any help will be appreciated.
Meteor.autorun(function () {
vm.loggedInUser = Meteor.user();
});
It's working fine but when I reload the page it returns undefined
Meteor.autorun(function () {
vm.loggedInUser = Meteor.user();
console.log("loggedInUser", vm.loggedInUser); // undefined
});
When you refresh the page Meteor.user()
will be undefined for a few cycles until its data has been retransmitted from server to client via websocket/ddp. It will eventually become defined and have the right data. Single-page applications like those built in Meteor don't usually require a page refresh but have to deal with the case of the user refreshing manually. A typical solution is to show a loading spinner until subscriptions and user data become ready.
Also it's Tracker.autorun()
not Meteor.autorun()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.