-
-
Save byteshiva/88c4c562005add8fca34d6ce596e2288 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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