Skip to content

Commit bea4eec

Browse files
feat: update Supabase client initialization and improve environment variable loading
1 parent 4d4b12a commit bea4eec

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

edurate/backend/config/supabase.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
import { createClient } from '@supabase/supabase-js';
88

9-
const supabaseUrl = process.env.SUPABASE_URL || 'https://uchwzvymdthndlumpqab.supabase.co';
9+
const supabaseUrl = process.env.SUPABASE_URL || 'https://lhhaskcrrtaquzcddxpd.supabase.co';
1010
const supabaseKey = process.env.SUPABASE_KEY;
1111

1212
if (!supabaseKey) {
13-
console.error("❌ Missing SUPABASE_KEY environment variable");
14-
process.exit(1);
13+
console.error("❌ Warning: SUPABASE_KEY not found in environment");
14+
// Don't exit - let the app continue
15+
} else {
16+
console.log("✅ Supabase client initialized");
1517
}
1618

1719
export const supabase = createClient(supabaseUrl, supabaseKey);
18-
19-
console.log("✅ Supabase client initialized");

edurate/backend/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
* Configures middleware, routes, and starts the server.
66
*/
77

8-
// 1. Load environment variables
9-
import dotenv from "dotenv";
10-
dotenv.config();
8+
// 1. Load environment variables FIRST
9+
import 'dotenv/config';
10+
11+
console.log("🔍 SUPABASE_KEY length:", process.env.SUPABASE_KEY?.length);
1112

1213
// 2. Import dependencies
1314
import express from "express";
@@ -16,7 +17,7 @@ import cors from "cors";
1617
// 3. Import routes and middleware
1718
import courseRoutes from './routes/courses.js';
1819
import { notFoundHandler, errorHandler } from './middleware/errorHandler.js';
19-
import { supabase } from './config/supabase.js';
20+
// DON'T import supabase here - it's imported inside the routes
2021

2122
// 4. Initialize Express app
2223
const app = express();
@@ -36,6 +37,9 @@ app.get("/", (req, res) => {
3637
});
3738

3839
app.get("/ping-supabase", async (req, res) => {
40+
// Import supabase only when needed
41+
const { supabase } = await import('./config/supabase.js');
42+
3943
try {
4044
const { data, error } = await supabase
4145
.from("courses")

0 commit comments

Comments
 (0)