Skip to content

Commit b2ba797

Browse files
committed
Adding Node.js Auth Token Claims
Adding Admin Node.js code snippets for https://firebase.google.com/docs/auth/admin/create-custom-tokens
1 parent 20d7b8c commit b2ba797

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

auth/create_custom_tokens.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Initialize the Admin app with the default appication credentials
2+
// [START initialize_sdk_with_default_config]
3+
admin.initializeApp();
4+
// [END initialize_sdk_with_default_config]
5+
6+
// Initialize the Admin app by providing a service accoune key
7+
// [START initialize_sdk_with_service_account_id]
8+
admin.initializeApp({
9+
serviceAccountId: '[email protected]',
10+
});
11+
// [END initialize_sdk_with_service_account_id]
12+
13+
// [START custom_token]
14+
var uid = "some-uid";
15+
16+
admin.auth().createCustomToken(uid)
17+
.then(function(customToken) {
18+
// Send token back to client
19+
})
20+
.catch(function(error) {
21+
console.log("Error creating custom token:", error);
22+
});
23+
// [END custom_token]
24+
25+
// [START custom_token_with_claims]
26+
var uid = "some-uid";
27+
var additionalClaims = {
28+
premiumAccount: true
29+
};
30+
31+
admin.auth().createCustomToken(uid, additionalClaims)
32+
.then(function(customToken) {
33+
// Send token back to client
34+
})
35+
.catch(function(error) {
36+
console.log("Error creating custom token:", error);
37+
});
38+
// [END custom_token_with_claims]

0 commit comments

Comments
 (0)