Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 435a151

Browse files
authored
Merge branch 'master' into ss-admin-auth-features
2 parents c469748 + 7fc82ae commit 435a151

40 files changed

+5946
-7376
lines changed

auth/create_custom_tokens.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,32 @@ admin.initializeApp({
1414
// [END initialize_sdk_with_service_account_id]
1515

1616
// [START custom_token]
17-
let uid = 'some-uid';
17+
const uid = 'some-uid';
1818

19-
admin.auth().createCustomToken(uid)
20-
.then(function(customToken) {
19+
admin
20+
.auth()
21+
.createCustomToken(uid)
22+
.then((customToken) => {
2123
// Send token back to client
2224
})
23-
.catch(function(error) {
25+
.catch((error) => {
2426
console.log('Error creating custom token:', error);
2527
});
2628
// [END custom_token]
2729

2830
// [START custom_token_with_claims]
29-
let userId = 'some-uid';
30-
let additionalClaims = {
31-
premiumAccount: true
31+
const userId = 'some-uid';
32+
const additionalClaims = {
33+
premiumAccount: true,
3234
};
3335

34-
admin.auth().createCustomToken(userId, additionalClaims)
35-
.then(function(customToken) {
36+
admin
37+
.auth()
38+
.createCustomToken(userId, additionalClaims)
39+
.then((customToken) => {
3640
// Send token back to client
3741
})
38-
.catch(function(error) {
42+
.catch((error) => {
3943
console.log('Error creating custom token:', error);
4044
});
4145
// [END custom_token_with_claims]

auth/custom_claims.js

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,72 @@ const idToken = 'some-invalid-token';
88
// [START set_custom_user_claims]
99
// Set admin privilege on the user corresponding to uid.
1010

11-
admin.auth().setCustomUserClaims(uid, {admin: true}).then(() => {
12-
// The new custom claims will propagate to the user's ID token the
13-
// next time a new one is issued.
14-
});
11+
admin
12+
.auth()
13+
.setCustomUserClaims(uid, { admin: true })
14+
.then(() => {
15+
// The new custom claims will propagate to the user's ID token the
16+
// next time a new one is issued.
17+
});
1518
// [END set_custom_user_claims]
1619

17-
1820
// [START verify_custom_claims]
1921
// Verify the ID token first.
20-
admin.auth().verifyIdToken(idToken).then((claims) => {
21-
if (claims.admin === true) {
22-
// Allow access to requested admin resource.
23-
}
24-
});
22+
admin
23+
.auth()
24+
.verifyIdToken(idToken)
25+
.then((claims) => {
26+
if (claims.admin === true) {
27+
// Allow access to requested admin resource.
28+
}
29+
});
2530
// [END verify_custom_claims]
2631

2732
// [START read_custom_user_claims]
2833
// Lookup the user associated with the specified uid.
29-
admin.auth().getUser(uid).then((userRecord) => {
30-
// The claims can be accessed on the user record.
31-
console.log(userRecord.customClaims['admin']);
32-
});
34+
admin
35+
.auth()
36+
.getUser(uid)
37+
.then((userRecord) => {
38+
// The claims can be accessed on the user record.
39+
console.log(userRecord.customClaims['admin']);
40+
});
3341
// [END read_custom_user_claims]
3442

3543
// [START set_custom_user_claims_script]
36-
admin.auth().getUserByEmail('[email protected]').then((user) => {
37-
// Confirm user is verified.
38-
if (user.emailVerified) {
39-
// Add custom claims for additional privileges.
40-
// This will be picked up by the user on token refresh or next sign in on new device.
41-
return admin.auth().setCustomUserClaims(user.uid, {
42-
admin: true
43-
});
44-
}
45-
})
44+
admin
45+
.auth()
46+
.getUserByEmail('[email protected]')
47+
.then((user) => {
48+
// Confirm user is verified.
49+
if (user.emailVerified) {
50+
// Add custom claims for additional privileges.
51+
// This will be picked up by the user on token refresh or next sign in on new device.
52+
return admin.auth().setCustomUserClaims(user.uid, {
53+
admin: true,
54+
});
55+
}
56+
})
4657
.catch((error) => {
4758
console.log(error);
4859
});
4960
// [END set_custom_user_claims_script]
5061

5162
// [START set_custom_user_claims_incremental]
52-
admin.auth().getUserByEmail('[email protected]').then((user) => {
53-
// Add incremental custom claim without overwriting existing claims.
54-
const currentCustomClaims = user.customClaims;
55-
if (currentCustomClaims['admin']) {
56-
// Add level.
57-
currentCustomClaims['accessLevel'] = 10;
58-
// Add custom claims for additional privileges.
59-
return admin.auth().setCustomUserClaims(user.uid, currentCustomClaims);
60-
}
61-
})
63+
admin
64+
.auth()
65+
.getUserByEmail('[email protected]')
66+
.then((user) => {
67+
// Add incremental custom claim without overwriting existing claims.
68+
const currentCustomClaims = user.customClaims;
69+
if (currentCustomClaims['admin']) {
70+
// Add level.
71+
currentCustomClaims['accessLevel'] = 10;
72+
// Add custom claims for additional privileges.
73+
return admin.auth().setCustomUserClaims(user.uid, currentCustomClaims);
74+
}
75+
})
6276
.catch((error) => {
6377
console.log(error);
6478
});
65-
// [END set_custom_user_claims_incremental]
79+
// [END set_custom_user_claims_incremental]

auth/email_action_links.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@ const actionCodeSettings = {
1010
// This must be true for email link sign-in.
1111
handleCodeInApp: true,
1212
iOS: {
13-
bundleId: 'com.example.ios'
13+
bundleId: 'com.example.ios',
1414
},
1515
android: {
1616
packageName: 'com.example.android',
1717
installApp: true,
18-
minimumVersion: '12'
18+
minimumVersion: '12',
1919
},
2020
// FDL custom domain.
21-
dynamicLinkDomain: 'coolapp.page.link'
21+
dynamicLinkDomain: 'coolapp.page.link',
2222
};
2323
// [END init_action_code_settings]
2424

2525
// [START password_reset_link]
2626
// Admin SDK API to generate the password reset link.
2727
const userEmail = '[email protected]';
28-
admin.auth().generatePasswordResetLink(userEmail, actionCodeSettings)
28+
admin
29+
.auth()
30+
.generatePasswordResetLink(userEmail, actionCodeSettings)
2931
.then((link) => {
3032
// Construct password reset email template, embed the link and send
3133
// using custom SMTP server.
@@ -39,7 +41,9 @@ admin.auth().generatePasswordResetLink(userEmail, actionCodeSettings)
3941
// [START email_verification_link]
4042
// Admin SDK API to generate the password reset link.
4143
const email = '[email protected]';
42-
admin.auth().generatePasswordResetLink(email, actionCodeSettings)
44+
admin
45+
.auth()
46+
.generatePasswordResetLink(email, actionCodeSettings)
4347
.then((link) => {
4448
// Construct password reset email template, embed the link and send
4549
// using custom SMTP server.
@@ -52,7 +56,9 @@ admin.auth().generatePasswordResetLink(email, actionCodeSettings)
5256
// [START email_verification_link]
5357
// Admin SDK API to generate the email verification link.
5458
const useremail = '[email protected]';
55-
admin.auth().generateEmailVerificationLink(useremail, actionCodeSettings)
59+
admin
60+
.auth()
61+
.generateEmailVerificationLink(useremail, actionCodeSettings)
5662
.then((link) => {
5763
// Construct email verification template, embed the link and send
5864
// using custom SMTP server.
@@ -66,7 +72,9 @@ admin.auth().generateEmailVerificationLink(useremail, actionCodeSettings)
6672
// [START sign_in_with_email_link]
6773
// Admin SDK API to generate the sign in with email link.
6874
const usremail = '[email protected]';
69-
admin.auth().generateSignInWithEmailLink(usremail, actionCodeSettings)
75+
admin
76+
.auth()
77+
.generateSignInWithEmailLink(usremail, actionCodeSettings)
7078
.then((link) => {
7179
// Construct sign-in with email link template, embed the link and
7280
// send using custom SMTP server.
@@ -78,13 +86,12 @@ admin.auth().generateSignInWithEmailLink(usremail, actionCodeSettings)
7886
// [END sign_in_with_email_link]
7987

8088
let displayName;
81-
function sendSignInEmail(...args) {
89+
const sendSignInEmail = (...args) => {
8290
// TODO: this function is just here to make the code "compile"
83-
}
84-
function sendCustomVerificationEmail(...args) {
85-
// TODO: this function is just here to make the code "compile"
86-
}
87-
function sendCustomPasswordResetEmail(...args) {
88-
// TODO: this function is just here to make the code "compile"
89-
}
90-
91+
};
92+
const sendCustomVerificationEmail = (...args) => {
93+
// TODO: this function is just here to make the code "compile"
94+
};
95+
const sendCustomPasswordResetEmail = (...args) => {
96+
// TODO: this function is just here to make the code "compile"
97+
};

auth/get_service_account_tokens.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ credential.getAccessToken().then((accessTokenInfo) => {
3131
// [END_EXCLUDE]
3232
});
3333
// [END get_service_account_tokens]
34-

0 commit comments

Comments
 (0)