Having issue in integrating custom authentication in my meteor server

i am completely new in meteor js and just started working on it few days ago

i am trying to integrate our custom authentication in our meteor project but i failed to do it for passed 2 days that why i came here to request help in resolving my issue.

Authentication Flow:

when ever user opens our meteor project site …first we check Meteor.user() is null or not if its null then we redirect user to “Authentication page” which is hosted on other domain … from there when user successfully log in … than we redirect him from that domain to our meteor project with token in the querystring

e.g. http://test.local.com/verifyToken?token=qweqweqweqwe

(my token length of char are more than 50+ char)

on “verifyToken” route we get the token and again verify it for with our main site domain for verification of token is valid or not.

i have created loginUser method on server side in which i am verifying user exist or not … and create new if needed. and insert the token in the database in services.resume.loginTokens

but the issue is it does set the user as current user even though database is getting update if i user (Push comment code ) … if i try to use current shared code it gives error on inserting in db

Meteor.methods({
   loginUser: function(email, username, token) {
   	  	   check(email, String);
   	  	   check(username, String);	
           check(String(token), String);
           var userId= Accounts.findUserByEmail(email);
          // var stampedLoginToken = Accounts._generateStampedLoginToken(); 
          var stampedLoginToken =   String(token); 
          var dateNow = (new Date()).toISOString();
          var userTokenData =  { 'when' : dateNow , 'hashedToken' : stampedLoginToken };

         if (!userId) {
           userId = Accounts.createUser({email: email, username: username, password: 'test123', verified: true});
          Accounts._insertLoginToken(userId._id, userTokenData );
          // following code works and insert value 
          // Meteor.users.update(userId, 
          //   {$push: {'services.resume.loginTokens': userTokenData}}
          // );
         }else{
          Accounts._insertLoginToken(userId._id, userTokenData ); 	
          // following code works and insert value 
          // Meteor.users.update(userId, 
          //   {$push: {'services.resume.loginTokens': userTokenData}}
          // );  
         }

         // but my user is not set 
         console.log("hey I'm", Meteor.user());


         return { 'token' : stampedLoginToken , 'when' : dateNow, id : userId._id };
          // return {
          //   id: userId._id,
          //   email: email,
          //   username: username,
          //   token: stampedLoginToken
          // };
   }
});

on client side i also tried to verify the returned token with

Meteor.loginwithtoken(token,function(err){

   if(err){ // always get this error if i use my custom token
        console.log(err);// getting error of 403
   }else{
         console.log('success');
         console.log('i am ' + Meteor.user());
   }

})

need help is resolving this issue as soon as possible … thanks in advance