javascript - In Meteor, how/where do I write code that triggers when an authorized user has logged in? -
new meteor, i'm using alanning:roles
package handle roles.
i've managed able publish collection when user logged in, when page first refreshed.
meteor.publish('col', function(){ if (roles.userisinrole(this.userid, 'admin')) { console.log('authed'); return sessions.find({}); } else { console.log('not auth'); // user unauthorized this.stop(); return; } });
logging out kills access collection (i'm using mongol see). logging in after logging out, or logging in logged out state when page first loaded, not give me access.
the webapp i'm trying build ticketing system. i'm trying secure, no unnecessary publishing if user not authorized.
what i'm trying is, ticket information submitted users collection, , display on client screen (as long client authorized first). maybe better way handle force refresh (how do that?) after user change unauthorized users "kicked" out? , render relevant data private collection right after user authorized?
i managed want helpers...
in ./client/subs.js
file:
meteor.subscribe('col'); template.newticket.helpers({ // match template name // move method later, not secure because on client?? isadmin() { console.log('is admin.'); console.log(meteor.userid()); meteor.subscribe('col'); return roles.userisinrole(meteor.userid(), 'admin'); }, });
and somewhere in template file ./client/partials/newticket.html
:
<template name="newticket"> {{#if isadmin}} {{/if}} </template>
to trigger check? i'm 99% sure theres better way.
Comments
Post a Comment