-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathcreate_custom_tokens.js
44 lines (38 loc) · 1.14 KB
/
create_custom_tokens.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
const { initializeApp } = require('firebase-admin/app');
const { getAuth } = require('firebase-admin/auth');
// Initialize the Admin app with the default appication credentials
// [START initialize_sdk_with_default_config]
initializeApp();
// [END initialize_sdk_with_default_config]
// Initialize the Admin app by providing a service accoune key
// [START initialize_sdk_with_service_account_id]
initializeApp({
serviceAccountId: 'my-client-id@my-project-id.iam.gserviceaccount.com',
});
// [END initialize_sdk_with_service_account_id]
// [START custom_token]
const uid = 'some-uid';
getAuth()
.createCustomToken(uid)
.then((customToken) => {
// Send token back to client
})
.catch((error) => {
console.log('Error creating custom token:', error);
});
// [END custom_token]
// [START custom_token_with_claims]
const userId = 'some-uid';
const additionalClaims = {
premiumAccount: true,
};
getAuth()
.createCustomToken(userId, additionalClaims)
.then((customToken) => {
// Send token back to client
})
.catch((error) => {
console.log('Error creating custom token:', error);
});
// [END custom_token_with_claims]