Skip to content

Commit

Permalink
Init functions folder
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewTurk247 committed Mar 16, 2024
1 parent b74930c commit 7224490
Show file tree
Hide file tree
Showing 7 changed files with 7,126 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "4215a748079614ed67aab303326e024c420507be5020eb9239ee1daf68db0025",
"pins" : [
{
"identity" : "abseil-cpp-binary",
Expand Down Expand Up @@ -50,17 +51,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk.git",
"state" : {
"revision" : "f91c8167141d0279726c6f6d9d4a47c026785cbc",
"version" : "10.21.0"
"revision" : "be49849dcba96f2b5ee550d4eceb2c0fa27dade4",
"version" : "10.22.1"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "cb8617fab75d181270a1d8f763f26b15c73e2e1e",
"version" : "10.21.0"
"revision" : "482cfa4e5880f0a29f66ecfd60c5a62af28bd1f0",
"version" : "10.22.1"
}
},
{
Expand Down Expand Up @@ -361,5 +362,5 @@
}
}
],
"version" : 2
"version" : 3
}
20 changes: 19 additions & 1 deletion firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,31 @@
"storage": {
"rules": "firebasestorage.rules"
},
"functions": [
{
"codebase": "callable-functions",
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
],
"source": "functions",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
}
],
"emulators": {
"auth": {
"port": 9099
},
"firestore": {
"port": 8080
},
"functions": {
"port": 5001
},
"ui": {
"enabled": true,
"port": 4000
Expand All @@ -21,4 +39,4 @@
},
"singleProjectMode": true
}
}
}
23 changes: 23 additions & 0 deletions functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// This source file is part of the StudyApplication based on the Stanford Spezi Template Application project
//
// SPDX-FileCopyrightText: 2023 Stanford University
//
// SPDX-License-Identifier: MIT
//

module.exports = {
root: true,
env: {
es2020: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
"quotes": ["error", "double"],
"max-len": ["error", {"code": 150}],
},
};
1 change: 1 addition & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
30 changes: 15 additions & 15 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,24 @@ exports.checkInvitationCode = onCall(async (request) => {
}
});

export const beforecreated = beforeUserCreated(async (event) => {
const firestore = admin.firestore();
exports.beforecreated = beforeUserCreated(async (event) => {
const firestore = admin.firestore();

try {
// Check Firestore to confirm whether an invitation code has been associated with a user.
const invitationQuerySnapshot = await firestore.collection("invitationCodes")
try {
// Check Firestore to confirm whether an invitation code has been associated with a user.
const invitationQuerySnapshot = await firestore.collection("invitationCodes")
.where("usedBy", "==", event.data.user.uid)
.limit(1)
.get();

if (invitationQuerySnapshot.empty) {
throw new https.HttpsError("no-match", "No valid invitation code found for this user.");
}
} catch (error) {
logger.error(`Error processing request: ${error.message}`);
if (!error.code) {
throw new https.HttpsError("internal", "Internal server error.");
}
throw error;
if (invitationQuerySnapshot.empty) {
throw new https.HttpsError("no-match", "No valid invitation code found for this user.");
}
} catch (error) {
logger.error(`Error processing request: ${error.message}`);
if (!error.code) {
throw new https.HttpsError("internal", "Internal server error.");
}
})
throw error;
}
});
Loading

0 comments on commit 7224490

Please sign in to comment.