From ae3e38a3afe5806d4cf4affd96269db42c51912c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20West=C3=B6=C3=B6?= Date: Sat, 24 Jan 2026 22:50:15 +0100 Subject: [PATCH] Fix script to handle new user with email verification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- deploy-to-apps.example.sh | 53 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/deploy-to-apps.example.sh b/deploy-to-apps.example.sh index 23f32ff..4d7ce09 100644 --- a/deploy-to-apps.example.sh +++ b/deploy-to-apps.example.sh @@ -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 ""