-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a9c44b
commit 05c35e6
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as functions from 'firebase-functions'; | ||
import { db } from "./firebaseConfig"; | ||
|
||
|
||
export const isUserInBlacklist = functions.https.onCall(async (data, context) => { | ||
const uid = data.uid; | ||
if (!uid) { | ||
throw new functions.https.HttpsError('invalid-argument', 'The function must be called with one argument "uid".'); | ||
} | ||
console.log(`Checking if user ${uid} is in the blacklist...`); | ||
|
||
try { | ||
const blacklistDocRef = db.doc("restrictions/blacklist"); | ||
const docSnap = await blacklistDocRef.get(); | ||
|
||
// Check if the document exists and has data | ||
if (docSnap.exists && docSnap.data()) { | ||
const blacklist = docSnap.data()?.list; | ||
return { isInBlacklist: Array.isArray(blacklist) && blacklist.some(user => user.uid === uid) }; | ||
} else { | ||
// Blacklist document does not exist or has no data | ||
return { isInBlacklist: false }; | ||
} | ||
} catch (error) { | ||
throw new functions.https.HttpsError('unknown', 'An error occurred while checking the blacklist', error); | ||
} | ||
}); |