Fix script to handle existing unverified user registration
When a user tries to register with an email that already exists but is not verified: - API now returns existing_user: true and api_key: null - Script detects existing_user flag - Loads existing API key from config file instead of expecting it in response - Shows appropriate message about new verification code being sent - Continues to verification step This fixes the error 'Failed to extract user data' when users re-register. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -279,15 +279,46 @@ else
|
||||
# Extract user data
|
||||
USER_ID=$(echo "$REGISTER_RESPONSE" | jq -r '.user_id')
|
||||
SAAC_API_KEY=$(echo "$REGISTER_RESPONSE" | jq -r '.api_key')
|
||||
EXISTING_USER=$(echo "$REGISTER_RESPONSE" | jq -r '.existing_user // false')
|
||||
VERIFICATION_SENT=$(echo "$REGISTER_RESPONSE" | jq -r '.verification_code_sent // false')
|
||||
|
||||
if [ "$USER_ID" = "null" ] || [ -z "$USER_ID" ] || [ "$SAAC_API_KEY" = "null" ] || [ -z "$SAAC_API_KEY" ]; then
|
||||
if [ "$USER_ID" = "null" ] || [ -z "$USER_ID" ]; then
|
||||
echo "❌ Failed to extract user data from registration response"
|
||||
echo "Response: $REGISTER_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ User registered!"
|
||||
echo " User ID: $USER_ID"
|
||||
# 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"
|
||||
|
||||
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 - 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
|
||||
|
||||
echo "✅ User registered!"
|
||||
echo " User ID: $USER_ID"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Save initial configuration (unverified)
|
||||
@@ -302,10 +333,16 @@ else
|
||||
|
||||
# Prompt for verification code
|
||||
echo "========================================="
|
||||
echo " Email Verification"
|
||||
echo " Email Verification Required"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
echo "📧 Verification email sent to: $USER_EMAIL"
|
||||
|
||||
if [ "$EXISTING_USER" = "true" ]; then
|
||||
echo "📧 New verification code sent to: $USER_EMAIL"
|
||||
else
|
||||
echo "📧 Verification email sent to: $USER_EMAIL"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "🔍 Check your email at MailHog:"
|
||||
echo " https://mailhog.goryan.io"
|
||||
|
||||
Reference in New Issue
Block a user