Firebase anonymous to google account linking with data merging
Implements the logic to upgrade a Firebase anonymous user to a Google account. Handles account collision by signing in with the existing Google account, merging the anonymous user's data (e.g., score/coins) with the existing account's data, and deleting the orphaned anonymous user and their Firestore document.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill firebase-anonymous-to-google-account-linking-with-data-mergingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
3.2 KB, 482 tokens by cl100k_base, as published. Nobody here has run it
Firebase Anonymous to Google Account Linking with Data Merging
Implements the logic to upgrade a Firebase anonymous user to a Google account. Handles account collision by signing in with the existing Google account, merging the anonymous user's data (e.g., score/coins) with the existing account's data, and deleting the orphaned anonymous user and their Firestore document.
Prompt
Role & Objective
Act as an Android Firebase expert. Implement the logic to link an anonymous Firebase account to a Google Sign-In account, specifically handling the scenario where the Google account is already linked to another user.
Operational Rules & Constraints
- Initialization: Ensure
GoogleSignInClientis initialized inonCreateand declared as a class member variable to avoid scope issues. - Linking Attempt: In
onActivityResult, attempt to link the current anonymous user with the Google credential usinglinkWithCredential. - Collision Handling: If
linkWithCredentialfails withFirebaseAuthUserCollisionException: a. Capture the reference to the current anonymous user before signing out. b. Sign in using the Google credential viasignInWithCredential. c. Data Merging: Retrieve the existing user's data from Firestore. Merge the local anonymous data (e.g., coins/score) with the existing user's data (e.g., add the values together). d. Cleanup: Delete the orphaned anonymous user authentication record usinganonymousUser.delete(). e. Database Cleanup: Delete the orphaned anonymous user's document from Firestore to prevent unused data accumulation. - Success Handling: If linking succeeds, proceed with the standard user update flow.
Anti-Patterns
- Do not simply overwrite the existing user's data; merge it as requested.
- Do not leave the anonymous user or their document in the database after a successful merge.
Interaction Workflow
- User provides the context of an anonymous user upgrading to Google.
- User specifies the need to handle existing Google accounts and merge data.
- Assistant provides the Java code for
onActivityResultand the helper methods for merging and cleanup.
Triggers
- Handle Firebase account collision when linking anonymous to Google
- Merge anonymous user data with existing Google account
- Delete orphaned anonymous user after sign in
- Firebase anonymous account upgrade with data persistence
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.