File tree Expand file tree Collapse file tree 4 files changed +51
-1
lines changed
solution-aggregation/functions
solution-deletes/functions Expand file tree Collapse file tree 4 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const admin = require ( 'firebase-admin' ) ;
3+
4+ // Initialize the Admin app with the default appication credentials
5+ // [START initialize_sdk_with_default_config]
6+ admin . initializeApp ( ) ;
7+ // [END initialize_sdk_with_default_config]
8+
9+ // Initialize the Admin app by providing a service accoune key
10+ // [START initialize_sdk_with_service_account_id]
11+ admin . initializeApp ( {
12+ serviceAccountId : 'my-client-id@my-project-id.iam.gserviceaccount.com' ,
13+ } ) ;
14+ // [END initialize_sdk_with_service_account_id]
15+
16+ // [START custom_token]
17+ var uid = 'some-uid' ;
18+
19+ admin . auth ( ) . createCustomToken ( uid )
20+ . then ( function ( customToken ) {
21+ // Send token back to client
22+ } )
23+ . catch ( function ( error ) {
24+ console . log ( 'Error creating custom token:' , error ) ;
25+ } ) ;
26+ // [END custom_token]
27+
28+ // [START custom_token_with_claims]
29+ var userId = 'some-uid' ;
30+ var additionalClaims = {
31+ premiumAccount : true
32+ } ;
33+
34+ admin . auth ( ) . createCustomToken ( userId , additionalClaims )
35+ . then ( function ( customToken ) {
36+ // Send token back to client
37+ } )
38+ . catch ( function ( error ) {
39+ console . log ( 'Error creating custom token:' , error ) ;
40+ } ) ;
41+ // [END custom_token_with_claims]
Original file line number Diff line number Diff line change @@ -15,7 +15,11 @@ function initializeApp() {
1515 credential : admin . credential . applicationDefault ( )
1616 } ) ;
1717
18- var db = admin . firestore ( ) ;
18+ const db = admin . firestore ( ) ;
19+ // [START_EXCLUDE]
20+ const settings = { timestampsInSnapshots : true } ;
21+ db . settings ( settings ) ;
22+ // [END_EXCLUDE]
1923
2024 // [END initialize_app]
2125 return db ;
Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ const functions = require('firebase-functions');
22const admin = require ( 'firebase-admin' ) ;
33
44const db = admin . firestore ( ) ;
5+ // [START_EXCLUDE]
6+ const settings = { timestampsInSnapshots : true } ;
7+ db . settings ( settings ) ;
8+ // [END_EXCLUDE]
59
610// [START aggregate_function]
711exports . aggregateRatings = functions . firestore
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const functions = require('firebase-functions');
44
55admin . initializeApp ( ) ;
66
7+
78/**
89 * Callable function that creates a custom auth token with the
910 * custom attribute "admin" set to true.
You can’t perform that action at this time.
0 commit comments