2525
2626// Function to update access token on db if user exists
2727async 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
5056async 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
6069async 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
7385async 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 ) ) {
0 commit comments