Skip to content

Commit f6b7fb2

Browse files
committed
Review comments
1 parent e6d1833 commit f6b7fb2

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

auth/manage_users.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ admin.auth().updateUser(uid, {
126126
// Link the user with a federated identity provider (like Google).
127127
admin.auth().updateUser(uid, {
128128
providerToLink: {
129-
uid: 'google_uid12345',
130-
providerId: 'google.com'
129+
providerId: 'google.com',
130+
uid: 'google_uid12345'
131131
}
132132
})
133133
.then(function(userRecord) {

auth/tenant_management.js

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,81 @@
11
const admin = require('firebase-admin');
22
admin.initializeApp();
33

4+
const tenantId = 'tenantId';
5+
6+
function createTenant() {
7+
// [START auth_create_tenant]
8+
admin.auth().tenantManager().createTenant({
9+
displayName: 'myTenant1',
10+
emailSignInConfig: {
11+
enabled: true,
12+
passwordRequired: false, // Email link sign-in enabled.
13+
},
14+
})
15+
.then((createdTenant) => {
16+
console.log(createdTenant.toJSON());
17+
})
18+
.catch((error) => {
19+
// Handle error.
20+
});
21+
// [END auth_create_tenant]
22+
}
23+
24+
function updateTenant() {
25+
// [START auth_update_tenant]
26+
admin.auth().tenantManager().updateTenant(tenantId, {
27+
displayName: 'updatedName',
28+
emailSignInConfig: {
29+
enabled: false, // Disable email provider.
30+
},
31+
})
32+
.then((updatedTenant) => {
33+
console.log(updatedTenant.toJSON());
34+
})
35+
.catch((error) => {
36+
// Handle error.
37+
});
38+
// [END auth_update_tenant]
39+
}
40+
41+
function deleteTenant() {
42+
// [START auth_delete_tenant]
43+
admin.auth().tenantManager().deleteTenant(tenantId)
44+
.then(() => {
45+
// Tenant deleted.
46+
})
47+
.catch((error) => {
48+
// Handle error.
49+
});
50+
// [END auth_delete_tenant]
51+
}
52+
53+
// [START auth_list_all_tentants]
54+
function listAllTenants(nextPageToken) {
55+
return admin.auth().tenantManager().listTenants(100, nextPageToken)
56+
.then((result) => {
57+
result.tenants.forEach((tenant) => {
58+
console.log(tenant.toJSON());
59+
});
60+
if (result.pageToken) {
61+
return listAllTenants(result.pageToken);
62+
}
63+
});
64+
}
65+
// [END auth_list_all_tentants]
66+
67+
468
function enableAnonymousSignIn() {
569
// [START auth_tenant_enable_anon]
670
const manager = admin.auth().tenantManager();
7-
manager.updateTenant('tenantId', {
8-
anonymousSignInEnabled: true,
9-
})
10-
.then(function(tenant) {
11-
console.log('Successfully updated tenant: ', JSON.stringify(tenant));
12-
})
13-
.catch(function(error) {
14-
console.log('Error updating tenant: ', JSON.stringify(error));
15-
});
71+
manager.updateTenant(tenantId, {
72+
anonymousSignInEnabled: true,
73+
})
74+
.then(function(tenant) {
75+
console.log('Successfully updated tenant: ', JSON.stringify(tenant));
76+
})
77+
.catch(function(error) {
78+
console.log('Error updating tenant: ', JSON.stringify(error));
79+
});
1680
// [END auth_tenant_enable_anon]
1781
}

0 commit comments

Comments
 (0)