Skip to content

Commit 0059466

Browse files
committed
login if users hasn't login
1 parent e616175 commit 0059466

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

scripts/setup_credential.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# Check Azure login status
2+
$azAccount = az account show 2>$null
3+
4+
if (-not $azAccount) {
5+
6+
Write-Host "🔐 Not logged in to Azure. Attempting to login..." -ForegroundColor Yellow
7+
$azureTenantId = azd env get-value AZURE_TENANT_ID
8+
az login --tenant $azureTenantId | Out-Null
9+
10+
if ($LASTEXITCODE -ne 0) {
11+
Write-Host "❌ Azure login failed. Exiting script." -ForegroundColor Red
12+
exit 1
13+
}
14+
15+
Write-Host "✅ Logged in to Azure successfully." -ForegroundColor Green
16+
} else {
17+
$accountInfo = $azAccount | ConvertFrom-Json
18+
Write-Host "✅ Already logged in as: $($accountInfo.user.name)" -ForegroundColor Green
19+
}
20+
121
# Prompt for username with validation
222
do {
323
$username = Read-Host -Prompt '👤 Create a new username for the web app (no spaces, at least 1 character)'

scripts/setup_credential.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
#!/bin/bash
22

3+
set -e
4+
5+
# Check if already logged in
6+
if ! az account show &>/dev/null; then
7+
echo -e "🔐 Not logged in to Azure. Attempting to login..."
8+
9+
azureTenantId=$(azd env get-value AZURE_TENANT_ID)
10+
if [[ -z "$azureTenantId" ]]; then
11+
echo "❌ AZURE_TENANT_ID is not set in the environment. Exiting."
12+
exit 1
13+
fi
14+
15+
az login --tenant "$azureTenantId" > /dev/null
16+
if [[ $? -ne 0 ]]; then
17+
echo "❌ Azure login failed. Exiting script."
18+
exit 1
19+
fi
20+
21+
echo "✅ Logged in to Azure successfully."
22+
else
23+
user=$(az account show --query user.name -o tsv)
24+
echo "✅ Already logged in as: $user"
25+
fi
26+
327
templateValidationMode="${TEMPLATE_VALIDATION_MODE}"
428

529
if [[ "$templateValidationMode" == true ]]; then

0 commit comments

Comments
 (0)