Skip to content

Instantly share code, notes, and snippets.

@deltaepsilon
Created March 25, 2017 23:06
Show Gist options
  • Save deltaepsilon/0308a59f9d3aec24bb049dc2fae38e7b to your computer and use it in GitHub Desktop.
Save deltaepsilon/0308a59f9d3aec24bb049dc2fae38e7b to your computer and use it in GitHub Desktop.
const function = require('firebase-functions');
functions.database.ref('queues/login/{uid}').onWrite(event => {
const config = functions.config();
// functions.config() returns your environment variables.
// In this case I have an array of my admin users' email addresses in accessControlLists.adminUsers
// It looks like ['[email protected]', '[email protected]']
const adminUsersString = config.['access-control-lists']['admin-users'];
const adminUsers = adminUsersString.split(',');
const user = event.data.val();
const userRef = event.data.adminRef.root.child('users').child(event.params.uid);
if (!user) return Promise.resolve();
user.lastLogin = Date.now();
if (adminUsers.includes(user.email)) {
user.isAdmin = true;
}
return userRef.update(user).then(() => {
return event.data.ref.remove();
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment