This repository has been archived on 2025-11-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
picohack-2022/functions/index.js
2022-10-01 14:38:20 +01:00

46 lines
1.3 KiB
JavaScript

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
exports.messageTester = functions.https.onRequest((request, response) => {
functions.logger.info("Message was requested", {structuredData: true});
response.send("Sending message");
});
exports.userCreated = functions.auth.user().onCreate((user) => {
return admin.auth().setCustomUserClaims(user.uid, {
admin: false,
role: undefined,
});
});
exports.roleDefined = functions.https.onCall((data, context) => {
if (data.role == "firstAider") {
admin.auth().setCustomUserClaims(user.uid, {
role: "firstAider",
});
} else {
return db.collection("users").doc(user.uid).set({
role: "patient",
});
}
});
exports.firstAiderCreated = functions.firestore.document("first-aiders/{userId}/")
.onCreate(async (snap, context) => {
admin.auth().setCustomUserClaims(snap.id, {
role: "firstAider",
});
});
exports.firstAiderCreated = functions.firestore.document("patients/{userId}/")
.onCreate(async (snap, context) => {
admin.auth().setCustomUserClaims(snap.id, {
role: "patient",
});
});
//patient firstAider