Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions packages/functions/src/auth/authorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,28 @@ const generatePolicy = (principalId, effect, resource) => {
};

export const handler = async (event) => {
console.log("Full Event:", JSON.stringify(event, null, 2));
console.log("HTTP Method:", event.requestContext?.httpMethod);
console.log("Resource:", event.methodArn);
console.log("Headers:", JSON.stringify(event.headers, null, 2));

// Always allow OPTIONS
if (event.httpMethod === "OPTIONS") {
console.log("Allowing OPTIONS request");
return generatePolicy("user", "Allow", event.methodArn);
}

try {
const authHeader =
event.headers?.Authorization || event.headers?.authorization;
console.log("Auth Header:", authHeader);


// reduntant check
if (!authHeader) {
console.log("No auth header found - denying request");
return generatePolicy("user", "Deny", event.methodArn);
}

const token = authHeader.startsWith("Bearer ")
? authHeader.slice(7)
: authHeader;
console.log("Token found, attempting verification");


const decodedToken = await admin.auth().verifyIdToken(token);
console.log("Token verified:", decodedToken.uid);


if (!decodedToken) {
console.log("Token verification failed");
return generatePolicy("user", "Deny", event.methodArn);
}

Expand Down
6 changes: 0 additions & 6 deletions packages/functions/src/config/firebase-config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import admin from "firebase-admin";

console.log(
"Service Account:",
process.env.FIREBASE_SERVICE_ACCOUNT?.substring(0, 50) + "..."
);

try {
const serviceAccount = JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT);
console.log("Parsed Service Account project_id:", serviceAccount.project_id);

admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
Expand Down
1 change: 0 additions & 1 deletion packages/functions/src/routes/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ itemsRouter.post("/", async (req, res) => {
.replace("{{image}}", dynamicContent.image)
.replace("{{url}}", dynamicContent.url);

console.log("Sending emails to:", emailArray);
await sendEmail(
emailArray,
`New Item Matches Your Search - ${name}`,
Expand Down
3 changes: 0 additions & 3 deletions packages/functions/src/routes/searches.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ searchRouter.post("/", async (req, res) => {
);

if (search.rows.length == 1) {
console.log("search.rows", search.rows);
// subscribe user to keyword notification if they aren't already subscribed to it
if (!search.rows[0].emails.includes(email)) {
const item = await client.query(
Expand All @@ -29,12 +28,10 @@ searchRouter.post("/", async (req, res) => {
[email, keyword]
);
res.status(201).json(item.rows[0]);
console.log("updated subscribers of", keyword);
} else {
res.json("email already subscribed to keyword");
}
} else {
console.log("search HERE", search);
// keyword doesn't exist in table yet, add new row
const item = await client.query(
`INSERT INTO ${searchesTable} (keyword, emails) VALUES($1, $2) RETURNING *`,
Expand Down
2 changes: 0 additions & 2 deletions packages/functions/src/util/sendEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const sendEmail = async (email, subject, message) => {
console.log("Error sending email", error);
return;
}

console.log(`Email sent to ${email}`, { data });
} catch (error) {
console.log("Error sending email", error);
}
Expand Down