-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathset-account-level.js
More file actions
49 lines (40 loc) · 1.27 KB
/
set-account-level.js
File metadata and controls
49 lines (40 loc) · 1.27 KB
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
45
46
47
48
49
const fb = require("firebase-admin");
const serviceAccount = require("../private/service-account.json");
// This script will convert a standard account into an admin account.
const email = "parallel@mcmill.co.uk"
const isCircleAdmin = true;
const isCircleDataAdmin = true;
const isEuclidAdmin = true;
//////////////////////////////////////
fb.initializeApp({
credential: fb.credential.cert(serviceAccount),
databaseURL: "https://parallel-beta-31dc4.firebaseio.com",
});
const setAdmin = () => {
const claims = {};
if (isCircleAdmin) claims['account_type'] = 'ADMIN'
if (isCircleDataAdmin) claims['circles_data_type'] = 'ADMIN';
if (isEuclidAdmin) claims['euclid_type'] = 'ADMIN'
return fb
.auth()
.getUserByEmail(email)
.then(user => fb.auth().setCustomUserClaims(user.uid, claims))
.then(() => console.log(`\n\nSet user "${email}" claims to ${JSON.stringify(claims)}`))
.catch((err) => {
err.message = `${err.message} - ${email}`;
throw err;
})
};
const run = async () => {
await setAdmin()
};
run()
.then(() => {
console.error("\n\nSuccess setting account level");
process.exit(0);
})
.catch((err) => {
console.error("\n\nError setting account level!");
console.error(err.message + "\n");
process.exit(1);
});