@@ -72,17 +72,21 @@ hooks:
7272 Write-Host ""
7373 Write-Host "===== Running Post-Deployment Configuration =====" -ForegroundColor Yellow
7474
75- # Assign Cosmos DB role to current user
76- Write-Host "Assigning Cosmos DB Data Contributor role..."
75+ Write-Host "Checking Azure authentication..."
7776
7877 # Check if user is logged in, if not prompt for login
7978 $signedUserId = az ad signed-in-user show --query id -o tsv 2>$null
8079 if (-not $signedUserId) {
8180 Write-Host "Not logged in to Azure. Please authenticate..." -ForegroundColor Yellow
8281 az login --use-device-code
83- $signedUserId = az ad signed-in-user show --query id -o tsv
82+ if ($LASTEXITCODE -ne 0) {
83+ Write-Host "Azure login failed. Cannot proceed without authentication." -ForegroundColor Red
84+ exit 1
85+ }
86+ $signedUserId = az ad signed-in-user show --query id -o tsv 2>$null
8487 }
85-
88+ # Assign Cosmos DB role to current user
89+ Write-Host "Assigning Cosmos DB Data Contributor role..."
8690 az cosmosdb sql role assignment create --resource-group $env:RESOURCE_GROUP_NAME --account-name $env:COSMOSDB_ACCOUNT_NAME --role-definition-id "00000000-0000-0000-0000-000000000002" --principal-id $signedUserId --scope "/" 2>$null
8791 if ($LASTEXITCODE -eq 0) {
8892 Write-Host " Cosmos DB role assigned successfully" -ForegroundColor Green
@@ -149,16 +153,23 @@ hooks:
149153 echo ""
150154 echo "===== Running Post-Deployment Configuration ====="
151155
152- # Assign Cosmos DB role to current user
153- echo "Assigning Cosmos DB Data Contributor role..."
156+ echo "Checking Azure authentication..."
154157
155158 # Check if user is logged in, if not prompt for login
156- signed_user_id=$(az ad signed-in-user show --query id -o tsv 2>/dev/null)
157- if [ -z "$signed_user_id" ]; then
159+ if ! signed_user_id=$(az ad signed-in-user show --query id -o tsv 2>/dev/null) || [ -z "$signed_user_id" ]; then
158160 echo "Not logged in to Azure. Please authenticate..."
159- az login --use-device-code
160- signed_user_id=$(az ad signed-in-user show --query id -o tsv)
161+ if ! az login --use-device-code; then
162+ echo "Azure login failed. Cannot proceed without authentication."
163+ exit 1
164+ fi
165+ if ! signed_user_id=$(az ad signed-in-user show --query id -o tsv 2>/dev/null) || [ -z "$signed_user_id" ]; then
166+ echo "Failed to authenticate. Please run 'az login' manually before deployment."
167+ exit 1
168+ fi
161169 fi
170+
171+ # Assign Cosmos DB role to current user
172+ echo "Assigning Cosmos DB Data Contributor role..."
162173
163174 az cosmosdb sql role assignment create \
164175 --resource-group "$RESOURCE_GROUP_NAME" \
0 commit comments