How to Unlink from Twitter/Facebook/etc

Hi everyone. I’ve been tasked with implementing Meteor.loginWith<externalService>. Unfortunately, I’ve looked all over for ways of “unlinking” a Meteor.user from their external service.

Now, in our service, we would like it if people eventually made standalone accounts with us. In order to implement this fully, I need a way of unlinking (and re-linking) users from external services which they used to sign up with. So I came up with a solution, but I would like feedback on the efficacy of this solution. If there’s a better way, I want to know about it.

Desired Effect

  1. User logs in with twitter via Meteor.loginWithTwitter.
  2. User goes to settings page and sees this:
  3. User adds an email and password through method calls utilizing Accounts.addEmail and Accounts.setPassword.
  4. Clicking unlink should keep the user logged in (with the email and password they set up earlier), but their Meteor.user gets the services.twitter removed (i.e. they get unlinked from Twitter).

Solution:

  1. When the user clicks “unlink”, we prompt them for their password.
  2. First, we log the user in (without logging them out of the external service) using their email and the password they just entered.
  3. Next, we call a method which removed services.twitter from their Meteor.user.
/*Do not use this code without proper error/security checks*/

//this is in a React component
_onUnlinkTwitterClick(){
  this.setState({passwordPrompt: true})
}
_onPasswordPromptFormSubmit(){
  const email = this.props.user.emails[0].address;
  Meteor.loginWithPassword(email, this.state.enteredPassword, (err)=>{
    if (err){return};
    Meteor.call('unlinkTwitter')
  }
}

//server
Meteor.methods({
  unlinkTwitter: function(){
    Meteor.users.update(this.userId,{$unset:{'services.twitter':true}})
  }
})

So, this is pretty simple and I don’t see why there wouldn’t be a package or built-in function for this. I haven’t checked Atmosphere, yet. If there’s a simpler way to do this (i.e. with built-in Meteor/Accounts methods), please do share. Thanks.