0

私はfirebaseサービスに反応してWebアプリケーションを作成しています。私はログイン画面にGoogleとFacebookのログインを持っているし、ログイン後に彼らの電話をリンクするオプションを取得します。私はFirebase Phone Authを使っています。ユーザーはすでに署名されており、電話を使用して認証します。私はFacebookの/ Googleアカウントで電話の認証ユーザーオブジェクトをリンクしたい。Web上のFirebaseのFacebookとGmailアカウントで電話番号をリンクします

ドキュメントを見て、私のユースケースに合った解決策を見つけることができませんでした。ヘルプは高く評価されます。

答えて

1

ここでは、目に見えないreCAPTCHAを使用して電話番号をGoogle/Facebookユーザーにリンクする簡単な例を示します。

// Sign in the Google user first. 
firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider()) 
    .then(function(result) { 
    // Google user signed in. Check if phone number added. 
    if (!result.user.phoneNumber) { 
     // Ask user for phone number. 
     var phoneNumber = window.prompt('Provide your phone number'); 
     // You also need to provide a button element signInButtonElement 
     // which the user would click to complete sign-in. 
     // Get recaptcha token. Let's use invisible recaptcha and hook to the button. 
     var appVerifier = new firebase.auth.RecaptchaVerifier(
      signInButtonElement, {size: 'invisible'}); 
     // This will wait for the button to be clicked the reCAPTCHA resolved. 
     return result.user.linkWithPhoneNumber(phoneNumber, appVerifier) 
     .then(function(confirmationResult) { 
      // Ask user to provide the SMS code. 
      var code = window.prompt('Provide your SMS code'); 
      // Complete sign-in. 
      return confirmationResult.confirm(code); 
     }) 
    } 
    }) 
    .catch(function(error) { 
    // console.log(error); 
    }); 
関連する問題