Skip to content

Commit 000c072

Browse files
committed
auth-functions
1 parent 37da9bf commit 000c072

File tree

3 files changed

+69
-153
lines changed

3 files changed

+69
-153
lines changed

auth/functions/custom_claims.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// [START auth_custom_claims_cloud_function]
22
const functions = require('firebase-functions');
3-
const admin = require('firebase-admin');
3+
const { initializeApp } = require('firebase-admin/app');
4+
const { getAuth } = require('firebase-admin/auth');
5+
const { getDatabase } = require('firebase-admin/database');
46

5-
admin.initializeApp();
7+
initializeApp();
68

79
// On sign up.
810
exports.processSignUp = functions.auth.user().onCreate(async (user) => {
@@ -19,10 +21,10 @@ exports.processSignUp = functions.auth.user().onCreate(async (user) => {
1921

2022
try {
2123
// Set custom user claims on this newly created user.
22-
await admin.auth().setCustomUserClaims(user.uid, customClaims);
24+
await getAuth().setCustomUserClaims(user.uid, customClaims);
2325

2426
// Update real-time database to notify client to force refresh.
25-
const metadataRef = admin.database().ref('metadata/' + user.uid);
27+
const metadataRef = getDatabase().ref('metadata/' + user.uid);
2628

2729
// Set the refresh time to the current UTC timestamp.
2830
// This will be captured on the client to force a token refresh.

auth/functions/package-lock.json

Lines changed: 62 additions & 148 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)