v1.6.2/admin dashboard

This commit is contained in:
2020-08-15 11:45:50 -04:00
parent 56cd151a04
commit 43dc657582
25 changed files with 15498 additions and 10 deletions
+6 -10
View File
@@ -1,4 +1,4 @@
const admin = require("firebase-admin");
const admin = require('firebase-admin');
const timeDiff = (ds1, ds2) => {
const d1 = new Date(ds1);
@@ -15,7 +15,7 @@ const cleanUser = async (pT, sT) => {
.listUsers(1000, pT)
.then((listUsersResult) => {
listUsersResult.users.forEach((userRecord) => {
if (timeDiff(userRecord.metadata.lastSignInTime, sT) >= 24 * 7) {
if (timeDiff(userRecord.metadata.lastRefreshTime, sT) >= 24) {
usersToDelete.push(userRecord.uid);
}
});
@@ -25,19 +25,17 @@ const cleanUser = async (pT, sT) => {
return;
})
.catch((error) => {
console.log("Error listing users:", error);
console.log('Error listing users:', error);
});
return usersToDelete;
};
module.exports = async (req, res) => {
console.info(`[START]\tWEBHOOKS/User Clean Up`);
res.status(200).send({ message: "User Clean Up Started" });
res.status(200).send({ message: 'User Clean Up Started' });
const startedTime = new Date();
const usersToDelete = await cleanUser(undefined, startedTime);
console.info(
`[PROGRESS]\tWEBHOOKS/User Clean Up\t# OF USERS ${usersToDelete.length}`
);
console.info(`[PROGRESS]\tWEBHOOKS/User Clean Up\t# OF USERS ${usersToDelete.length}`);
admin
.auth()
.deleteUsers(usersToDelete)
@@ -46,7 +44,5 @@ module.exports = async (req, res) => {
`[ERROR]\tWEBHOOKS/User Clean Up\t# OF USERS ${usersToDelete.length},\tERROR:${err}`
)
);
console.info(
`[DONE]\tWEBHOOKS/User Clean Up\t# OF USERS ${usersToDelete.length}`
);
console.info(`[DONE]\tWEBHOOKS/User Clean Up\t# OF USERS ${usersToDelete.length}`);
};