Skip to content

Commit c8e42f4

Browse files
authored
Merge pull request firebase#31 from firebase/add_installation_snippets
add installation snippets
2 parents f003ef8 + 5bdaa57 commit c8e42f4

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

installations/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

installations/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "installations",
3+
"version": "1.0.0",
4+
"description": "",
5+
"scripts": {},
6+
"author": "",
7+
"license": "Apache 2.0",
8+
"dependencies": {
9+
"firebase": "^7.16.1"
10+
}
11+
}

0 commit comments

Comments
 (0)