diff --git a/auth/manage_users.js b/auth/manage_users.js index 46521d62..6e70ddae 100644 --- a/auth/manage_users.js +++ b/auth/manage_users.js @@ -48,6 +48,17 @@ admin }); // [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() @@ -132,6 +143,37 @@ admin }); // [END update_user] +// [START update_user_link_federated] +// Link the user with a federated identity provider (like Google). +admin.auth().updateUser(uid, { + providerToLink: { + providerId: 'google.com', + uid: 'google_uid12345' + } + }) + .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() diff --git a/auth/tenant_management.js b/auth/tenant_management.js new file mode 100644 index 00000000..a3d3858e --- /dev/null +++ b/auth/tenant_management.js @@ -0,0 +1,71 @@ +const admin = require('firebase-admin'); +admin.initializeApp(); + +const tenantId = 'tenantId'; + +function createTenant() { + // [START auth_create_tenant] + admin.auth().tenantManager().createTenant({ + displayName: 'myTenant1', + emailSignInConfig: { + enabled: true, + // Email link sign-in enabled. + passwordRequired: false, + }, + }) + .then((createdTenant) => { + console.log(createdTenant.toJSON()); + }) + .catch((error) => { + // Handle error. + }); + // [END auth_create_tenant] +} + +function updateTenant() { + // [START auth_update_tenant] + admin.auth().tenantManager().updateTenant(tenantId, { + displayName: 'updatedName', + emailSignInConfig: { + // Disable email provider. + enabled: false, + }, + // Enable anonymous sign-in + anonymousSignInEnabled: true, + }) + .then((updatedTenant) => { + console.log(updatedTenant.toJSON()); + }) + .catch((error) => { + // Handle error. + }); + // [END auth_update_tenant] +} + +function deleteTenant() { + // [START auth_delete_tenant] + admin.auth().tenantManager().deleteTenant(tenantId) + .then(() => { + // Tenant deleted. + }) + .catch((error) => { + // Handle error. + }); + // [END auth_delete_tenant] +} + +// [START auth_list_all_tenants] +function listAllTenants(nextPageToken) { + return admin.auth().tenantManager().listTenants(100, nextPageToken) + .then((result) => { + result.tenants.forEach((tenant) => { + console.log(tenant.toJSON()); + }); + if (result.pageToken) { + return listAllTenants(result.pageToken); + } + }); +} + +listAllTenants(); +// [END auth_list_all_tenants]