-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
10 changed files
with
156 additions
and
791 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"projects": { | ||
"default": "demo-project" | ||
} | ||
"production": "the-scene-social-app" | ||
}, | ||
"targets": {}, | ||
"etags": {}, | ||
"dataconnectEmulatorConfig": {} | ||
} |
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
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 |
---|---|---|
@@ -1,65 +1,63 @@ | ||
//Cloud functions | ||
|
||
const { logger } = require("firebase-functions"); | ||
const { onRequest } = require("firebase-functions/v2/https"); | ||
const { onDocumentCreated } = require("firebase-functions/v2/firestore"); | ||
const { onCall } = require("firebase-functions/v2/https"); | ||
|
||
// The Firebase Admin SDK to access Firestore. | ||
const { initializeApp } = require("firebase-admin/app"); | ||
const { getFirestore } = require("firebase-admin/firestore"); | ||
|
||
initializeApp(); | ||
|
||
// Create and deploy your first functions | ||
// https://firebase.google.com/docs/functions/get-started | ||
const db = getFirestore(); | ||
const usersCollection = db.collection("users"); | ||
|
||
// exports.helloWorld = onRequest((request, response) => { | ||
// logger.info("Hello logs!", { structuredData: true }); | ||
// response.send("Hello from Firebase!"); | ||
// }); | ||
exports.isEmailUsed = onCall(async (request) => { | ||
const email = request.data.email; | ||
|
||
exports.isEmailUsed = onRequest(async (request, response) => { | ||
const userEmail = request.query.email; | ||
try { | ||
//get user by email | ||
const usersSnapshot = await getFirestore() | ||
.collection("users") | ||
.where("email", "==", userEmail) | ||
.get(); | ||
const snapshot = await usersCollection.where("email", "==", email).get(); | ||
|
||
//if email exists return true | ||
if (!usersSnapshot.empty) { | ||
response.status(200).send(true); | ||
if (snapshot.empty) { | ||
console.log("No matching email."); | ||
return { | ||
emailUsed: false, | ||
}; | ||
} | ||
|
||
if (usersSnapshot.empty) { | ||
response.status(200).send(false); | ||
} | ||
return { | ||
emailUsed: true, | ||
}; | ||
} catch (error) { | ||
console.error("Error getting users collection:", error); | ||
response.status(500).send("Internal Server Error"); | ||
|
||
return { | ||
emailUsed: "bad", | ||
}; | ||
} | ||
}); | ||
|
||
exports.isUsernameUsed = onRequest(async (request, response) => { | ||
const username = request.query.username; | ||
exports.isUsernameUsed = onCall(async (request) => { | ||
const username = request.data.username; | ||
|
||
try { | ||
//get user by username | ||
const usersSnapshot = await getFirestore() | ||
.collection("users") | ||
//get user by email | ||
const snapshot = await usersCollection | ||
.where("username", "==", username) | ||
.get(); | ||
|
||
//if username exists return true | ||
if (!usersSnapshot.empty) { | ||
response.status(200).send(true); | ||
if (snapshot.empty) { | ||
console.log("No matching username."); | ||
return { | ||
isUsernameUsed: false, | ||
}; | ||
} | ||
|
||
if (usersSnapshot.empty) { | ||
response.status(200).send(false); | ||
} | ||
return { | ||
isUsernameUsed: true, | ||
}; | ||
} catch (error) { | ||
console.error("Error getting users collection:", error); | ||
response.status(500).send("Internal Server Error"); | ||
return { | ||
isUsernameUsed: "bad", | ||
}; | ||
} | ||
}); |
Oops, something went wrong.