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 :
'[email protected] ' ,
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() {
15
15
credential : admin . credential . applicationDefault ( )
16
16
} ) ;
17
17
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]
19
23
20
24
// [END initialize_app]
21
25
return db ;
Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ const functions = require('firebase-functions');
2
2
const admin = require ( 'firebase-admin' ) ;
3
3
4
4
const db = admin . firestore ( ) ;
5
+ // [START_EXCLUDE]
6
+ const settings = { timestampsInSnapshots : true } ;
7
+ db . settings ( settings ) ;
8
+ // [END_EXCLUDE]
5
9
6
10
// [START aggregate_function]
7
11
exports . aggregateRatings = functions . firestore
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const functions = require('firebase-functions');
4
4
5
5
admin . initializeApp ( ) ;
6
6
7
+
7
8
/**
8
9
* Callable function that creates a custom auth token with the
9
10
* custom attribute "admin" set to true.
You can’t perform that action at this time.
0 commit comments