Skip to content

Commit 0fd0398

Browse files
committed
Snippets for new Auth admin features
1 parent e58de8e commit 0fd0398

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

auth/manage_users.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ admin.auth().getUserByPhoneNumber(phoneNumber)
3535
});
3636
// [END get_user_by_phone]
3737

38+
// [START get_user_by_federated_id]
39+
admin.auth().getUserByProviderUid('google.com', 'google_uid1234')
40+
.then(function(userRecord) {
41+
// See the UserRecord reference doc for the contents of userRecord.
42+
console.log('Successfully fetched user data:', userRecord.toJSON());
43+
})
44+
.catch(function(error) {
45+
console.log('Error fetching user data:', error);
46+
});
47+
// [END get_user_by_federated_id]
48+
3849
// [START bulk_get_users]
3950
admin.auth().getUsers([
4051
{ uid: 'uid1' },
@@ -111,6 +122,37 @@ admin.auth().updateUser(uid, {
111122
});
112123
// [END update_user]
113124

125+
// [START update_user_link_federated]
126+
// Link the user with a federated identity provider (like Google).
127+
admin.auth().updateUser(uid, {
128+
providerToLink: {
129+
uid: 'google_uid12345',
130+
providerId: 'google.com'
131+
}
132+
})
133+
.then(function(userRecord) {
134+
// See the UserRecord reference doc for the contents of userRecord.
135+
console.log('Successfully updated user', userRecord.toJSON());
136+
})
137+
.catch(function(error) {
138+
console.log('Error updating user:', error);
139+
});
140+
// [END update_user_link_federated]
141+
142+
// [START update_user_unlink_federated]
143+
// Unlink the user from a federated identity provider (like Google).
144+
admin.auth().updateUser(uid, {
145+
providersToDelete: ['google.com']
146+
})
147+
.then(function(userRecord) {
148+
// See the UserRecord reference doc for the contents of userRecord.
149+
console.log('Successfully updated user', userRecord.toJSON());
150+
})
151+
.catch(function(error) {
152+
console.log('Error updating user:', error);
153+
});
154+
// [END update_user_unlink_federated]
155+
114156
// [START delete_user]
115157
admin.auth().deleteUser(uid)
116158
.then(function() {

auth/tenant_management.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const admin = require('firebase-admin');
2+
admin.initializeApp();
3+
4+
function enableAnonymousSignIn() {
5+
// [START auth_tenant_enable_anon]
6+
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+
});
16+
// [END auth_tenant_enable_anon]
17+
}

0 commit comments

Comments
 (0)