Fix script to handle new user with email verification
Problem: New users with email verification enabled receive api_key: null, but script only checked for existing_user flag, not null API key. Solution: Check if api_key is null first, then determine if it's: - Existing unverified user (load key from config) - New user with verification (api_key comes after verification) - New user without verification (api_key provided immediately) This fixes the 'Failed to extract API key' error for new registrations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -288,35 +288,42 @@ else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Handle existing unverified user (api_key will be null)
|
||||
if [ "$EXISTING_USER" = "true" ]; then
|
||||
echo "ℹ️ User already exists but not verified"
|
||||
echo " User ID: $USER_ID"
|
||||
# Check if API key is null (happens when email verification is enabled)
|
||||
if [ "$SAAC_API_KEY" = "null" ] || [ -z "$SAAC_API_KEY" ]; then
|
||||
# API key will be provided after email verification
|
||||
if [ "$EXISTING_USER" = "true" ]; then
|
||||
echo "ℹ️ User already exists but not verified"
|
||||
echo " User ID: $USER_ID"
|
||||
|
||||
if [ "$VERIFICATION_SENT" = "true" ]; then
|
||||
echo " ✅ New verification code sent!"
|
||||
else
|
||||
echo " ⚠️ Failed to send verification email"
|
||||
fi
|
||||
|
||||
# Load existing API key from config if it exists
|
||||
if [ -f "$SAAC_CONFIG_FILE" ]; then
|
||||
EXISTING_API_KEY=$(jq -r '.saac_api_key // ""' "$SAAC_CONFIG_FILE")
|
||||
if [ -n "$EXISTING_API_KEY" ] && [ "$EXISTING_API_KEY" != "null" ]; then
|
||||
SAAC_API_KEY="$EXISTING_API_KEY"
|
||||
echo " 🔑 Using existing API key from config"
|
||||
if [ "$VERIFICATION_SENT" = "true" ]; then
|
||||
echo " ✅ New verification code sent!"
|
||||
else
|
||||
echo " ⚠️ Failed to send verification email"
|
||||
fi
|
||||
|
||||
# Load existing API key from config if it exists
|
||||
if [ -f "$SAAC_CONFIG_FILE" ]; then
|
||||
EXISTING_API_KEY=$(jq -r '.saac_api_key // ""' "$SAAC_CONFIG_FILE")
|
||||
if [ -n "$EXISTING_API_KEY" ] && [ "$EXISTING_API_KEY" != "null" ]; then
|
||||
SAAC_API_KEY="$EXISTING_API_KEY"
|
||||
echo " 🔑 Using existing API key from config"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# New user with email verification enabled
|
||||
echo "✅ User registered!"
|
||||
echo " User ID: $USER_ID"
|
||||
echo " Email verification required"
|
||||
echo ""
|
||||
|
||||
# API key will be null - will get it after verification
|
||||
SAAC_API_KEY=""
|
||||
fi
|
||||
else
|
||||
# New user - api_key should be present
|
||||
if [ "$SAAC_API_KEY" = "null" ] || [ -z "$SAAC_API_KEY" ]; then
|
||||
echo "❌ Failed to extract API key from registration response"
|
||||
echo "Response: $REGISTER_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# API key provided - email verification disabled
|
||||
echo "✅ User registered!"
|
||||
echo " User ID: $USER_ID"
|
||||
echo " 🔑 API key received"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user