Right way to return result from Publish only for logged-in users and prevent application freeze in Flowrouter waitOn method?
I created method checkPermissions() which make an Meteor.Error, in case of user is not logged in for prevent return data for logged-out users. But If I make Meteor.logout() on client, application will freeze with white screen (don’t redirect to login page), because It is still waiting for response from publish. How to solve it with right way?
Route example:
adminRoutes.route('/schemes', {
name: 'admin.schemes',
action() {
this.render('layout', 'adminSchemes', {
contentTitle: 'adminSchemesTitle'
});
},
waitOn(params) {
return [
import('./views/admin/schemes/adminSchemes_script'),
Meteor.subscribe('settings_public')
];
}
});
Publish example:
Meteor.publish("adminUserFullnames", function () {
checkPermissions();
return Meteor.users.find({}, {fields: {'profile.fullname': 1}});
});
Check permissions method:
export const checkPermissions = () => {
if (!currentUserIsInRole('admin')) {
throw new Meteor.Error("Access denied!");
}
}