-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_creds.ts
More file actions
50 lines (43 loc) · 1.63 KB
/
get_creds.ts
File metadata and controls
50 lines (43 loc) · 1.63 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
import { createClient } from '@supabase/supabase-js';
import fs from 'fs';
import path from 'path';
// Load .env.local
const envPath = path.resolve(__dirname, '.env.local');
try {
const envContent = fs.readFileSync(envPath, 'utf-8');
const env: Record<string, string> = {};
envContent.split('\n').forEach(line => {
const match = line.match(/^([^=]+)=(.*)$/);
if (match) {
env[match[1]] = match[2].replace(/^"|"$/g, '');
}
});
const supabaseUrl = env['NEXT_PUBLIC_SUPABASE_URL'];
const supabaseKey = env['NEXT_PUBLIC_SUPABASE_ANON_KEY'];
if (!supabaseUrl || !supabaseKey) {
console.error("Missing credentials");
process.exit(1);
}
const supabase = createClient(supabaseUrl, supabaseKey);
async function fetchCreds() {
console.log("Fetching team...");
// Fetch a team that hasn't submitted a problem statement yet if possible
const { data: teams, error } = await supabase
.from('team')
.select('name, password, problem_stat')
.is('problem_stat', null)
.limit(1);
if (error) {
console.error("Error:", error);
} else if (teams && teams.length > 0) {
console.log("CREDENTIALS:", JSON.stringify(teams[0]));
} else {
console.log("No teams found without problem statement? Fetching any team...");
const { data: anyTeam } = await supabase.from('team').select('name, password').limit(1);
console.log("CREDENTIALS:", JSON.stringify(anyTeam?.[0]));
}
}
fetchCreds();
} catch (e) {
console.error(e);
}