-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapply-rls-overrides.js
More file actions
50 lines (40 loc) · 1.52 KB
/
Copy pathapply-rls-overrides.js
File metadata and controls
50 lines (40 loc) · 1.52 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
// Script to apply RLS policy overrides for development
const { createClient } = require('@supabase/supabase-js');
const fs = require('fs');
const path = require('path');
// Read environment variables from .env file
require('dotenv').config();
// Initialize Supabase client with service role key for admin access
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
if (!supabaseUrl || !supabaseServiceKey) {
console.error('Error: Supabase URL or service role key is missing.');
console.error('Make sure you have a .env file with NEXT_PUBLIC_SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY.');
process.exit(1);
}
// Create Supabase client with service role key
const supabase = createClient(supabaseUrl, supabaseServiceKey, {
auth: {
autoRefreshToken: false,
persistSession: false
}
});
// Read the SQL file
const sqlFilePath = path.join(__dirname, 'supabase', 'rls_dev_override.sql');
const sql = fs.readFileSync(sqlFilePath, 'utf8');
async function applyRlsOverrides() {
try {
console.log('Applying RLS policy overrides...');
// Execute the SQL queries
const { error } = await supabase.rpc('exec_sql', { sql });
if (error) {
console.error('Error applying RLS policy overrides:', error);
return;
}
console.log('RLS policy overrides applied successfully!');
console.log('You can now add doctors without authentication.');
} catch (error) {
console.error('Error:', error);
}
}
applyRlsOverrides();