From 95b09d4e75953e60d88a116bffb57745dab3b24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20West=C3=B6=C3=B6?= Date: Sat, 24 Jan 2026 22:27:05 +0100 Subject: [PATCH] Fix script to handle existing unverified user registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- deploy-to-apps.example.sh | 47 ++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) 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"