Substitutes the real admin UID everywhere the placeholder appeared, points the Edge Functions base URL at the deployed project, and adds production JWT verification: trigger functions now send the anon key as a bearer token so verify_jwt can stay enabled instead of leaving the functions open to unauthenticated calls from the public internet. Also adds scripts/create-admin.ts (one-off helper used to create Mira's admin auth user), documents the seed script's non-VITE env vars in .env.example, and closes a gitignore gap where plain .env wasn't excluded alongside .env.local. Claude-Session: https://claude.ai/code/session_01NhxA4npAXAxmCDEJt6kxSH
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { createClient } from '@supabase/supabase-js'
|
|
|
|
const supabaseUrl = process.env.SUPABASE_URL
|
|
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY
|
|
const adminEmail = process.env.ADMIN_EMAIL
|
|
const adminPassword = process.env.ADMIN_PASSWORD
|
|
|
|
if (!supabaseUrl || !serviceRoleKey) {
|
|
console.error('Set SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY environment variables before running this script.')
|
|
process.exit(1)
|
|
}
|
|
|
|
if (!adminEmail || !adminPassword) {
|
|
console.error('Set ADMIN_EMAIL and ADMIN_PASSWORD environment variables before running this script.')
|
|
process.exit(1)
|
|
}
|
|
|
|
const supabase = createClient(supabaseUrl, serviceRoleKey)
|
|
|
|
async function createAdmin() {
|
|
const { data, error } = await supabase.auth.admin.createUser({
|
|
email: adminEmail,
|
|
password: adminPassword,
|
|
email_confirm: true,
|
|
})
|
|
|
|
if (error) {
|
|
console.error('Failed to create admin user:', error.message)
|
|
process.exit(1)
|
|
}
|
|
|
|
console.log('Admin user created.')
|
|
console.log('UID:', data.user.id)
|
|
}
|
|
|
|
createAdmin()
|