Repository navigation
Expand file tree
/
Copy pathtest-connection.js
More file actions
68 lines (56 loc) · 1.97 KB
/
Copy pathtest-connection.js
File metadata and controls
68 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { createClient } from '@supabase/supabase-js';
import dotenv from 'dotenv';
// Load environment variables
dotenv.config();
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
console.log('🔧 Testing Supabase connection...');
console.log('URL:', supabaseUrl);
console.log('Service Role Key:', supabaseServiceRoleKey ? 'Present' : 'Missing');
const supabase = createClient(supabaseUrl, supabaseServiceRoleKey, {
auth: {
autoRefreshToken: false,
persistSession: false
}
});
async function testConnection() {
try {
console.log('\n📊 Fetching students...');
const { data: students, error } = await supabase
.from('students')
.select('*')
.limit(3);
if (error) {
console.error('❌ Error:', error);
return;
}
console.log('✅ Students found:', students.length);
students.forEach(student => {
console.log(`- ${student.register_number}: password="${student.password}"`);
});
// Test specific authentication with existing students
const testCredentials = [
{ registerNumber: 'CS2025', password: 'student123' },
{ registerNumber: 'STU001', password: 'QWE123' },
{ registerNumber: '963524104021', password: '12345678' }
];
for (const cred of testCredentials) {
console.log(`\n🔐 Testing authentication for ${cred.registerNumber}...`);
const { data: student, error: authError } = await supabase
.from('students')
.select('*')
.eq('register_number', cred.registerNumber)
.single();
if (authError) {
console.error('❌ Auth Error:', authError);
} else {
console.log('✅ Found student:', student);
console.log('Password in DB:', student.password);
console.log(`Password match test (${cred.password}):`, student.password === cred.password);
}
}
} catch (err) {
console.error('❌ Connection failed:', err);
}
}
testConnection();