Help us understand the problem. What is going on with this article?

firebaseを用いて匿名認証からTwitterアカウントを後から繋げる

まずはコードから。
コピペで動くと思います!

export const persistLoginWithTwitter = () => async dispatch => {
  var provider = new firebase.auth.TwitterAuthProvider();
  var anonymous_user = await firebase.auth().currentUser
  await anonymous_user.linkWithPopup(provider).then(function (usercred) {
  console.log('アカウントの紐付け成功')
 }, function (error) {
    console.log("Error upgrading anonymous account", error);
  });
}

これで普通に匿名ログイン中のユーザーをtwitterアカウントに繋げることができます。
注意するべきことは、
linkWithPopUp.then() の内部において、usercred.userをしてもtwitterのuser情報は出てこないところです。

var twitter_user = usercred.user.providerData[0]

こんな感じでtwitterのphotoURLとかdisplayNameが欲しいときは取り出します。
anonymousUserUpdateアクションで自分はdisplayNameとうが欲しかったので。。

実際にはこんな感じになりました。

export const persistLoginWithTwitter = () => async dispatch => {
  var provider = new firebase.auth.TwitterAuthProvider();
  var anonymous_user = await firebase.auth().currentUser
  await anonymous_user.linkWithPopup(provider).then(function (usercred) {
    var twitter_user = usercred.user.providerData[0]
    console.log(user)
    console.log(user.photoURL)
    dispatch(anonymousUserUpdate(twitter_user, anonymous_user.uid))
  }, function (error) {
    console.log("Error upgrading anonymous account", error);
  });
}
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away