简体   繁体   中英

Access user doc created with social sign up

I have two separate ways for a user to sign up to the site. One way is just simple signup and the other is a referral signup where the route has a token in it that relates to the userId of the person who referred them something like this:

Router.route('referral-signup', { path: '/referral-signup/:userId'});

In this referral route, I use a Meteor method call to create a doc in the referral table structured like: {refereeId: String, referrerId: String, verified: false} that holds all the relevant info on the referee and referrer as well as if the referee's email has been verified.

Both of the signup flows allow for the user to use Twitter or Facebook (regular signup & referral signup). The problem is that the Meteor method for a user Signing up with these social platforms looks like this:

Meteor.loginWithTwitter({}, function(error) {
    if (error) {
        throw new Meteor.Error("Twitter login failed.");
    } else {
        Router.go('home');
        return;
    }
});  

In this function callback, I can't seem to be able to access the user that was created and thus can not make the meteor method call to create the referral doc, which is a problem if a user is referred and then signs up through a social platform. Does anyone have any ideas on how to access the user within a social signup callback?

The approach I've taken in a similar situation is to put the referral token into a session variable when the referral route is called (in the route code itself). When the user is created I use the session variable to set the referrer info and then clear it. This also helps in cases where the new visitor pokes around the site for awhile before actually signing up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM