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.

  1. before condition fires
  2. (on client)serviceconfiguration.configurations has no configuration
  3. client has exception no linkedin service defined.
  4. 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

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -