Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions auth/manage_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ admin.auth().getUserByPhoneNumber(phoneNumber)
});
// [END get_user_by_phone]

// [START get_user_by_federated_id]
admin.auth().getUserByProviderUid('google.com', 'google_uid1234')
.then(function(userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully fetched user data:', userRecord.toJSON());
})
.catch(function(error) {
console.log('Error fetching user data:', error);
});
// [END get_user_by_federated_id]

// [START bulk_get_users]
admin.auth().getUsers([
{ uid: 'uid1' },
Expand Down Expand Up @@ -111,6 +122,37 @@ admin.auth().updateUser(uid, {
});
// [END update_user]

// [START update_user_link_federated]
// Link the user with a federated identity provider (like Google).
admin.auth().updateUser(uid, {
providerToLink: {
uid: 'google_uid12345',
providerId: 'google.com'
}
})
.then(function(userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully updated user', userRecord.toJSON());
})
.catch(function(error) {
console.log('Error updating user:', error);
});
// [END update_user_link_federated]

// [START update_user_unlink_federated]
// Unlink the user from a federated identity provider (like Google).
admin.auth().updateUser(uid, {
providersToDelete: ['google.com']
})
.then(function(userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully updated user', userRecord.toJSON());
})
.catch(function(error) {
console.log('Error updating user:', error);
});
// [END update_user_unlink_federated]

// [START delete_user]
admin.auth().deleteUser(uid)
.then(function() {
Expand Down
17 changes: 17 additions & 0 deletions auth/tenant_management.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const admin = require('firebase-admin');
admin.initializeApp();

function enableAnonymousSignIn() {
// [START auth_tenant_enable_anon]
const manager = admin.auth().tenantManager();
manager.updateTenant('tenantId', {
anonymousSignInEnabled: true,
})
.then(function(tenant) {
console.log('Successfully updated tenant: ', JSON.stringify(tenant));
})
.catch(function(error) {
console.log('Error updating tenant: ', JSON.stringify(error));
});
// [END auth_tenant_enable_anon]
}