Skip to content

Commit 3ede472

Browse files
committed
fix
1 parent 19e6264 commit 3ede472

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/backend/db.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ try {
2525

2626
// Function to update access token on db if user exists
2727
async function checkUser(accessToken: string, provider: string) {
28+
// Check if database connection is available
29+
if (!userAuthCollection) {
30+
console.error("Database connection not available. userAuthCollection is undefined.");
31+
throw new Error("Database connection not available. Please check MONGO_URI environment variable and MongoDB connectivity.");
32+
}
33+
2834
const userId = await getProviderUser(accessToken, provider);
2935

3036
// Use ADMIN_LIST to check if user is allowed
@@ -48,6 +54,9 @@ async function checkUser(accessToken: string, provider: string) {
4854

4955
// Get all content maps corresponding to user
5056
async function getMaps(author: string, ADMIN_LIST: string[]) {
57+
if (!contentMapsCollection) {
58+
throw new Error("Database connection not available.");
59+
}
5160
const filter = ADMIN_LIST?.includes(author) ? {} : { "author": author };
5261

5362
// Convert deprecated simple filter to standard mongo filter if needed
@@ -58,6 +67,9 @@ async function getMaps(author: string, ADMIN_LIST: string[]) {
5867

5968
// Add content maps
6069
async function addMaps(document: DfContentMap) {
70+
if (!contentMapsCollection) {
71+
throw new Error("Database connection not available.");
72+
}
6173
// Check existence
6274
const existing = await contentMapsCollection.findOne({ "subdomain": document.subdomain });
6375

@@ -71,6 +83,9 @@ async function addMaps(document: DfContentMap) {
7183

7284
// Delete content maps
7385
async function deleteMaps(document: DfContentMap, ADMIN_LIST: string[]) {
86+
if (!contentMapsCollection) {
87+
throw new Error("Database connection not available.");
88+
}
7489
const filter: any = { ...document };
7590
// Native driver deleteOne expects a filter object
7691
if (ADMIN_LIST.includes(document.author)) {

src/backend/dependencies.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { create, verify } from "https://deno.land/x/djwt@v2.9.1/mod.ts";
1010
import { exec } from "https://deno.land/x/exec@0.0.5/mod.ts";
1111
import * as Sentry from 'https://deno.land/x/sentry/index.mjs';
1212
import { oakCors } from "https://deno.land/x/cors@v1.2.2/mod.ts";
13+
import "https://deno.land/std@0.224.0/dotenv/load.ts";
1314
import { MongoClient, ObjectId } from "https://deno.land/x/mongo@v0.32.0/mod.ts";
1415

1516
export {

0 commit comments

Comments
 (0)