-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadminUpdateUserRole.js
More file actions
25 lines (21 loc) · 946 Bytes
/
adminUpdateUserRole.js
File metadata and controls
25 lines (21 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const functions = require('firebase-functions');
const { db, auth } = require('../shared/admin.js');
const { checkArguments } = require('../shared/helpers.js');
const { adminUpdateUserRole } = require('../actions/userRoles')(db, auth);
module.exports = functions.region('europe-west2').https.onCall(async (data, context) => {
if (!context.auth) {
throw new functions.https.HttpsError('failed-precondition', 'The function must be called while authenticated.');
}
if (!checkArguments({
roleId: { required: true },
enabledPermissions: { required: false },
}, data)) {
throw new functions.https.HttpsError('invalid-argument', 'Please provide valid arguments');
}
// validate input parameters
if (!Array.isArray(data.enabledPermissions)) {
throw new functions.https.HttpsError('invalid-argument', 'Please provide valid arguments');
}
//TODO: add role check here
return await adminUpdateUserRole(data);
});