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
4 changes: 2 additions & 2 deletions auth/manage_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ admin.auth().updateUser(uid, {
// Link the user with a federated identity provider (like Google).
admin.auth().updateUser(uid, {
providerToLink: {
uid: 'google_uid12345',
providerId: 'google.com'
providerId: 'google.com',
uid: 'google_uid12345'
}
})
.then(function(userRecord) {
Expand Down
82 changes: 73 additions & 9 deletions auth/tenant_management.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,81 @@
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,
passwordRequired: false, // Email link sign-in enabled.
},
})
.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: {
enabled: false, // Disable email provider.
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally, I had thought to just piggy-back the enablement of anon authentication docs into the existing create/update tenant docs. My reasoning was that this is just another parameter, not really much different than (eg) emailSignInConfig. If you did that here, you could get rid of the enableAnonAuth snippet entirely. (No objection to keeping it separate either though.)

})
.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_tentants]
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);
}
});
}
// [END auth_list_all_tentants]


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));
});
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]
}