This guide helps resolve common authentication issues when deploying the Hackerspace Mumbai site to Netlify through GitHub Actions or local development.
Symptoms:
- GitHub Actions deploy-preview job fails
- Error message: "Timed out waiting for authorization"
- Netlify CLI attempts interactive authentication in CI
Root Cause:
The Netlify CLI is trying to use browser-based authentication instead of the provided NETLIFY_AUTH_TOKEN.
Solutions:
# In GitHub Actions, verify secrets are set:
# Go to Repository Settings > Secrets and variables > Actions
# Ensure these secrets exist:
# - NETLIFY_AUTH_TOKEN
# - NETLIFY_SITE_ID# Test your token locally:
export NETLIFY_AUTH_TOKEN="your_token_here"
netlify status --jsonEnsure your package.json scripts use explicit site ID:
{
"deploy:preview": "netlify deploy --site=$NETLIFY_SITE_ID --dir=dist --functions=netlify/functions",
"deploy:preview:ci": "netlify deploy --site=$NETLIFY_SITE_ID --dir=dist --functions=netlify/functions --json"
}Symptoms:
- "Authentication required" error
- "Invalid token" error
- 401 Unauthorized responses
Solutions:
- Go to Netlify User Settings > Applications
- Click "New access token"
- Give it a descriptive name (e.g., "GitHub Actions Deploy")
- Copy the generated token
- Update GitHub repository secret
# Test token validity:
curl -H "Authorization: Bearer YOUR_TOKEN" \
https://api.netlify.com/api/v1/user- Netlify tokens don't expire, but they can be revoked
- If token was revoked, generate a new one
- Update all environments using the old token
Symptoms:
- "Site not found" error
- Interactive site selection prompt in CI
- Deployment to wrong site
Solutions:
- Go to Netlify dashboard
- Select your site
- Navigate to Site Settings > General
- Copy "Site ID" from Site Information section
# Site ID should be a UUID-like string:
# Example: 12345678-1234-1234-1234-123456789abc
echo $NETLIFY_SITE_ID# Verify you can access the site:
export NETLIFY_AUTH_TOKEN="your_token"
export NETLIFY_SITE_ID="your_site_id"
netlify api getSite --data='{"site_id":"'$NETLIFY_SITE_ID'"}'Symptoms:
- Secrets not available in workflow
- Environment variables not set
- Workflow fails at credential verification step
Solutions:
# Ensure secrets are properly referenced in workflow:
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}- Secret names are case-sensitive
- No spaces or special characters allowed
- Must match exactly in workflow file
Add this step to your workflow for debugging:
- name: Debug Netlify credentials
run: |
echo "Token length: ${#NETLIFY_AUTH_TOKEN}"
echo "Site ID: $NETLIFY_SITE_ID"
netlify status --json
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}Symptoms:
- Local deployment fails
- Interactive login prompts
- Different behavior between local and CI
Solutions:
# Create .env file (don't commit this):
echo "NETLIFY_AUTH_TOKEN=your_token_here" >> .env
echo "NETLIFY_SITE_ID=your_site_id_here" >> .env
# Or export directly:
export NETLIFY_AUTH_TOKEN="your_token_here"
export NETLIFY_SITE_ID="your_site_id_here"# Verify authentication works:
netlify status
# Test deployment:
pnpm build
pnpm deploy:preview# Run with Netlify dev server:
netlify dev
# This automatically handles authenticationBest Practices:
- Always use
--jsonflag for structured output - Include credential verification step before deployment
- Use GitHub Actions error annotations for better visibility
- Implement retry logic for network issues
Example Workflow Step:
- name: Verify Netlify credentials
run: |
if [ -z "$NETLIFY_AUTH_TOKEN" ]; then
echo "::error::NETLIFY_AUTH_TOKEN is not set"
exit 1
fi
if [ -z "$NETLIFY_SITE_ID" ]; then
echo "::error::NETLIFY_SITE_ID is not set"
exit 1
fi
netlify status --json
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}Best Practices:
- Use environment variables instead of interactive login
- Test authentication before attempting deployment
- Keep local and CI authentication methods consistent
- Use
.envfiles for local development (add to.gitignore)
Setup Script:
#!/bin/bash
# setup-local-deploy.sh
echo "Setting up local Netlify deployment..."
if [ -z "$NETLIFY_AUTH_TOKEN" ]; then
echo "Please set NETLIFY_AUTH_TOKEN environment variable"
exit 1
fi
if [ -z "$NETLIFY_SITE_ID" ]; then
echo "Please set NETLIFY_SITE_ID environment variable"
exit 1
fi
echo "Testing authentication..."
netlify status
echo "Local deployment setup complete!"# Basic status check:
netlify status
# Detailed JSON output:
netlify status --json
# Check specific site:
netlify api getSite --data='{"site_id":"YOUR_SITE_ID"}'# Dry run deployment:
netlify deploy --dir=dist --dry-run
# Deploy with debug output:
DEBUG=netlify* netlify deploy --dir=dist# Check current configuration:
netlify env:list
# Validate site access:
netlify sites:list
# Test API connectivity:
curl -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
https://api.netlify.com/api/v1/sites/$NETLIFY_SITE_ID- Add credential validation to deployment scripts
- Implement pre-deployment checks in CI/CD
- Use structured logging for better debugging
- Keep deployment documentation up to date
- Document environment-specific requirements
- Provide troubleshooting examples
- Monitor deployment success rates
- Set up alerts for authentication failures
- Track deployment duration and error patterns
- Rotate tokens regularly
- Use least-privilege access
- Audit token usage and permissions
- Check this troubleshooting guide
- Review Netlify Deployment Configuration
- Check project README.md deployment section
- Create GitHub issue with deployment logs
- Check Netlify status page for service issues
- Review GitHub Actions workflow logs
# Check authentication
netlify status
# List available sites
netlify sites:list
# Deploy preview
netlify deploy --dir=dist
# Deploy production
netlify deploy --prod --dir=dist
# Get deployment info
netlify api listSiteDeploys --data='{"site_id":"YOUR_SITE_ID"}'# Required for deployment
NETLIFY_AUTH_TOKEN=your_personal_access_token
NETLIFY_SITE_ID=your_site_uuid
# Optional for debugging
DEBUG=netlify*
NODE_ENV=production- 401 Unauthorized: Invalid or missing auth token
- 404 Not Found: Invalid site ID or insufficient permissions
- 422 Unprocessable Entity: Invalid deployment parameters
- 429 Too Many Requests: Rate limiting (wait and retry)