1
+ const firebase = require ( "firebase" ) ;
2
+
3
+ async function deleteInstallation ( ) {
4
+ try {
5
+ // [START delete_installation]
6
+ await firebase . installations ( ) . delete ( ) ;
7
+ // [END delete_installation]
8
+ } catch ( err ) {
9
+ console . error ( 'Unable to delete installation: ' , err ) ;
10
+ }
11
+ }
12
+
13
+ async function getInstallationId ( ) {
14
+ try {
15
+ // [START get_installation_id]
16
+ const installationId = await firebase . installations ( ) . getId ( ) ;
17
+ console . log ( installationId ) ;
18
+ // [END get_installation_id]
19
+ } catch ( err ) {
20
+ console . error ( 'Unable to get Installation ID: ' , err ) ;
21
+ }
22
+ }
23
+
24
+ async function getAuthenticationToken ( ) {
25
+ try {
26
+ // [START get_auth_token]
27
+ const authToken = await firebase . installations ( )
28
+ . getToken ( /* forceRefresh */ true ) ;
29
+ console . log ( authToken ) ;
30
+ // [END get_auth_token]
31
+ } catch ( err ) {
32
+ console . error ( 'Unable to get auth token: ' , err ) ;
33
+ }
34
+ }
35
+
36
+ async function setOnIdChangeHandler ( ) {
37
+ try {
38
+ // [START set_id_change_handler]
39
+ await firebase . installations ( ) . onIdChange ( ( newId ) => {
40
+ console . log ( newId ) ;
41
+ // TODO: Handle new installation ID.
42
+ } ) ;
43
+ // [START set_id_change_handler]
44
+ } catch ( err ) {
45
+ console . error ( 'Unable to set ID change handler: ' , err ) ;
46
+ }
47
+ }
0 commit comments