meteor - Race condition when going directly secured page -
i running race condition when unknown user trying access secured page.
iron-router code:
function secured() { if ( meteor.user() == null ) { meteor.loginwithlinkedin({ },function (err){ if(err){ console.log("error when login linkedin."+json.stringify(err)); } }); } } router.map(function () {this.route('customer_researchrequest', { before: secured, waiton: waitonhuman, path: '/research/request', template: 'customer_researchrequest', layouttemplate: 'customer_requestlayout' });}); on server:
serviceconfiguration.configurations.remove({ service: 'linkedin' }); serviceconfiguration.configurations.insert({... settings ...}); if user goes directly /research/request, there race condition.
- before condition fires
- (on client)serviceconfiguration.configurations has no configuration
- client has exception no linkedin service defined.
- server publishes serviceconfiguration.configurations client
at point, solution hard code in clientid , other linkedin config information linkedin authentication code ( yech ).
is there better more elegant/correct solution?
update #1: solution tweak meteor-linkedin package expects linkedin clientid option , not depend on serviceconfiguration.configuration. way clientid available.
edited address comment:
maybe different use of reactivity can help. set deferred redirect customer_researchrequest, first diverting user, bringing them up
a) have secured() save original destination path session. redirect page allow without security (or 'loading...' page), avoid #3
b) when login callback happens, save flag session, indicating #4 no longer true c) have deps.autorun redirect desired path when both flags become true.
someone else may know smarter way, (maybe waiton should test config) ...
Comments
Post a Comment