firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Google Popup Auth Overides Twitter Popup data on Authentication Tab

Open loarsaw opened this issue 1 year ago • 0 comments

Operating System

Windows 11

Browser Version

Chrome/121.0.6167.185

Firebase SDK Version

9.18.0

Firebase SDK Product:

Auth

Describe your project's tooling

Nextjs - 13.2.4 Firebase - 9.18.0

Describe the problem

I have Two Login Methods

  1. Login with Google (Popup)
  2. Login with Twitter (Popup)

If you are logged in with Google you can link you twitter as one revieves an error code

auth/account-exists-with-different-credential

If I signup with Google and then with Twitter then I am recieving the above mentioned error so I can use the link the two accounts but the if signup with twitter and then again login with Google I dont recieve ```auth/account-exists-with-different-credential and twitter is overriden by Google login method and now upon login with twitter

Step 1 : Signup with Google

image

Step 2 : Sign Up with twitter , Since already there with Google it will throw an error and we can use

linkWithPopup(auth.currentUser, provider);

and then image

Deleted User now start with twitter image

Now If I use Google image

Woosh !

Steps and code to reproduce issue

export async function twitterSignIn() {
  const provider = new TwitterAuthProvider();
  try {
    const result = await signInWithPopup(auth, provider);
    const user = result.user;
    console.log("IN TWIS");
    const { isNewUser }= getAdditionalUserInfo(result);
    console.log(isNewUser);
    if (isNewUser) {
      await setUserProfile(user, 13);
    }
  } catch (error) {
    if (error.code == "auth/account-exists-with-different-credential") {
         googleSignIn().then(() => {
            linkWithPopup(auth.currentUser, provider);
          });
        },
      });
    }
  }
}
export async function googleSignIn(randomNumber: number) {
  const provider = new GoogleAuthProvider();
  console.log("INPR");
  try {
    const result = await signInWithPopup(auth, provider);
    const user = result.user;
    console.log("DOne")
    console.log(user);
    const { isNewUser }: any = getAdditionalUserInfo(result);
    console.log(isNewUser);
    if (isNewUser) {
      await setUserProfile(user, randomNumber);
    }
  } catch (error: any) {
    if (error.code == "auth/account-exists-with-different-credential") {
   
    
          twitterSignIn().then(()=>{
          linkWithPopup(auth.currentUser, provider);})
  
  
    console.log(error);
  }
}

loarsaw avatar Feb 18 '24 04:02 loarsaw