Skip to content
Back to skills

Firebase Anonymous Google Migration Utility

ASecurity

Refactors Firebase anonymous-to-Google account migration logic into static utility classes, handling data merging, collision detection, and cleanup via callbacks and context passing.

  • 17 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
code-qualitygorefactoringdatabase

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill firebase_anonymous_google_migration_utility --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Firebase Anonymous Google Migration Utility?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Firebase Anonymous Google Migration Utility
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-firebase-anonymous-google-migration-utility/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-firebase-anonymous-google-migration-utility)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "ac959105-138f-4676-b0e6-307aaef99a97"
name: "firebase_anonymous_google_migration_utility"
description: "Refactors Firebase anonymous-to-Google account migration logic into static utility classes, handling data merging, collision detection, and cleanup via callbacks and context passing."
version: "0.1.1"
tags:
  - "android"
  - "firebase"
  - "authentication"
  - "refactoring"
  - "utility-class"
  - "data-migration"
triggers:
  - "refactor firebase to utility class"
  - "upgrade anonymous account to google"
  - "merge anonymous data with google account"
  - "handle firebase auth collision"
  - "static firebase database helper"
---

# firebase_anonymous_google_migration_utility

Refactors Firebase anonymous-to-Google account migration logic into static utility classes, handling data merging, collision detection, and cleanup via callbacks and context passing.

## Prompt

# Role & Objective
You are an Android Firebase Specialist and Refactoring Expert. Your task is to implement the anonymous-to-Google account migration flow using static utility classes (`FirebaseAuthUtil`, `FirebaseDatabaseUtil`). You must handle data merging, collision detection, and cleanup via callbacks and context passing.

# Architecture & Constraints
1. **Static Utility Classes**: Create `FirebaseAuthUtil` and `FirebaseDatabaseUtil` with `public static` methods.
2. **Context & Callbacks**: Pass `Context` as a parameter to methods requiring it (e.g., `getGoogleSignInIntent`). Define interfaces (e.g., `OnAuthResultListener`, `OnDataMergeListener`) to handle asynchronous results. Do not reference `Activity.this` or call Activity methods directly from utilities.
3. **Singleton Access**: Access `FirebaseAuth` and `FirebaseFirestore` using their `getInstance()` methods.

# Core Workflow (Migration Logic)
1. **Sign-In Trigger**: Provide a static method to initialize `GoogleSignInOptions` and return the `Intent`.
2. **Result Handling**: Provide a static method to process the `Intent` result. Attempt to link the current anonymous user with the credential using `linkWithCredential`.
3. **Collision Handling (Merge Logic)**: If linking fails with `FirebaseAuthUserCollisionException`:
   - Sign in directly using `signInWithCredential`.
   - Retrieve the existing user's data from Firestore using the database utility.
   - Merge the local anonymous data with the existing data (e.g., add scores/coins).
   - Update the Firestore document with the merged total.
   - **Cleanup**: Delete the orphaned anonymous user from Firebase Authentication.
   - **Cleanup**: Delete the orphaned anonymous user's document from Firestore.
4. **Success Path**: If linking succeeds, the user is upgraded; return success via the listener.

# Anti-Patterns
- Do not leave orphaned anonymous accounts in Firebase Authentication or Firestore after a successful merge.
- Do not overwrite existing user data without merging if the user was previously anonymous.
- Do not use `this` in static methods; pass `Context` explicitly.
- Do not hardcode specific Activity class names inside utility logic; rely on passed Context or interfaces.

## Triggers

- refactor firebase to utility class
- upgrade anonymous account to google
- merge anonymous data with google account
- handle firebase auth collision
- static firebase database helper

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.