Files
webshop/scripts/init_supabase.sh
DanielS 4402d4ec64
Some checks failed
Staging Build / build (push) Failing after 25s
Add SMTP mail utility, admin settings page, and API routes for SMTP configuration and test email
2026-06-23 00:17:41 +02:00

36 lines
1.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
# Initialize Supabase if needed and ensure default admin user exists
# Requires environment variables:
# SUPABASE_URL base URL of Supabase instance (e.g., http://192.168.1.132:8000)
# SUPABASE_SERVICE_ROLE_KEY service role secret key with admin privileges
# DEFAULT_USER_EMAIL email for the default user (default: info@hephex.de)
# DEFAULT_USER_PASSWORD password for the default user (default: Kathi2022!)
DEFAULT_EMAIL="${DEFAULT_USER_EMAIL:-info@hephex.de}"
DEFAULT_PASSWORD="${DEFAULT_USER_PASSWORD:-Kathi2022!}"
if [[ -z "$SUPABASE_URL" || -z "$SUPABASE_SERVICE_ROLE_KEY" ]]; then
echo "Supabase URL or Service Role Key not set skipping user creation."
exit 0
fi
# Check if the user already exists
EXISTING=$(curl -s "${SUPABASE_URL}/auth/v1/admin/users?apikey=${SUPABASE_SERVICE_ROLE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_SERVICE_ROLE_KEY}" \
-H "Content-Type: application/json" | grep -i "${DEFAULT_EMAIL}")
if [[ -n "$EXISTING" ]]; then
echo "Default user ${DEFAULT_EMAIL} already exists."
else
echo "Creating default user ${DEFAULT_EMAIL}..."
curl -s -X POST "${SUPABASE_URL}/auth/v1/admin/users?apikey=${SUPABASE_SERVICE_ROLE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_SERVICE_ROLE_KEY}" \
-H "Content-Type: application/json" \
-d "{\"email\": \"${DEFAULT_EMAIL}\", \"password\": \"${DEFAULT_PASSWORD}\", \"email_confirmed\": true}"
echo "User created."
fi
exec "$@"