diff --git a/deploy-to-apps.example.sh b/deploy-to-apps.example.sh index b95984d..aa737e8 100644 --- a/deploy-to-apps.example.sh +++ b/deploy-to-apps.example.sh @@ -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"