firebase-to-supabase
firebase-to-supabase copied to clipboard
Dealing with users who have multiple auth providers
Bug report
Describe the bug
I’m curious if others have encountered this problem or know of a workaround. I’m having issues authenticating users in Supabase who have multiple auth providers associated with their accounts in Firebase.
For instance, if someone signs up with Apple and later changes their email and password, Firebase will associate both an email auth and an Apple auth with that user. After running the import, I encounter problems when trying to sign in as that user in Supabase. It recognizes it as a new account and doesn’t retrieve the associated Firebase UID or information.
I’ve attempted to modify the export script firestoreusers2json to loop over providers and create separate users for each provider. Here’s an example:
async function listUsers(filename, batchSize, nextPageToken) {
let count = 0;
try {
const listUsersResult = await admin
.auth()
.listUsers(batchSize, nextPageToken);
const users = listUsersResult.users;
users.forEach(user => {
const userProviders = user.providerData;
if (userProviders.length > 1) {
userProviders.forEach(provider => {
const providerUser = {
...user,
email: provider.email,
providerData: [provider],
originalUid: user.uid,
};
fs.appendFileSync(
filename,
(count > 0 ? ',' : '') + JSON.stringify(providerUser, null, 2),
'utf-8'
);
count++;
});
} else {
fs.appendFileSync(
filename,
(count > 0 ? ',' : '') + JSON.stringify(user, null, 2),
'utf-8'
);
count++;
}
});
if (listUsersResult.pageToken) {
fs.appendFileSync(filename, ',', 'utf-8');
await listUsers(filename, batchSize, listUsersResult.pageToken);
}
} catch (err) {
console.log('ERROR in listUsers', JSON.stringify(err));
}
}
This seems to work initially; the user in Supabase appears to contain the Firebase data (fbuser). However, when attempting to sign in using Apple, this data gets overwritten. Signing in using the email and password, however, seems to retain the fbuser data.
To Reproduce
- Create account in firebase with Apple Sign In
- Change email and password using firebase auth Javascript SDK
- Run firebase-to-supabase user migration scripts.
- Attempt to sign in with Apple
- User loses fbuser data.
Expected behavior
I'd expect this to be handled the same way Firebase handles multiple providers. Sign in with any provider attached to the account, and get access to the same user.