three-blocks-login
v0.1.12
Published
Fetch a short-lived token from the three-blocks broker and configure npm for the current context.
Maintainers
Readme
three-blocks-login
Minimal, dependency-free CLI for authenticating to Three Blocks private npm registry (AWS CodeArtifact).
Quick Start
# Interactive login (writes to .npmrc in current directory)
npx -y three-blocks-login@latest
# Using pnpm (recommended - no warnings)
npx -y three-blocks-login@latest@latestAuthentication Modes
The CLI supports three modes for storing authentication:
1. Project Mode (Default)
Writes .npmrc to the current directory. Best for project-specific authentication.
npx -y three-blocks-login@latest --mode project --scope @three-blocks --channel stableFor CI/CD: Run this command BEFORE pnpm install, not as a preinstall hook. See CI/CD Setup for platform-specific examples.
Note: Flags are optional - the CLI auto-detects --mode project in CI environments, defaults to --scope @three-blocks, and --channel stable.
2. Env Mode (Temporary)
Writes to a temporary .npmrc file and exports NPM_CONFIG_USERCONFIG. Useful for shell sessions.
eval "$(npx -y three-blocks-login@latest --mode env --print-shell)"3. User Mode (Global)
Updates your user's npm config (~/.npmrc). Affects all projects.
npx -y three-blocks-login@latest --mode userCLI Options
| Option | Description | Default |
|--------|-------------|---------|
| --mode <env\|project\|user> | Authentication storage mode | Auto-detected |
| --scope <scope> | npm scope to authenticate | @three-blocks |
| --channel <stable\|alpha\|beta> | Release channel | stable or THREE_BLOCKS_CHANNEL env |
| --license <key> | License key (or use THREE_BLOCKS_SECRET_KEY env) | From env or prompt |
| --endpoint <url> | Custom broker endpoint | https://www.threejs-blocks.com/api/npm/token |
| --quiet / -q | Suppress non-error output | false |
| --verbose / -v | Enable verbose logging | false |
| --debug | Enable debug logging | false |
| --non-interactive | Fail instead of prompting | false or CI=1 |
| --print-shell | Print shell export commands (env mode) | false or THREE_BLOCKS_LOGIN_PRINT_SHELL=1 |
Environment Variables
| Variable | Description |
|----------|-------------|
| THREE_BLOCKS_SECRET_KEY | License key (format: tb_...) |
| THREE_BLOCKS_CHANNEL | Release channel (stable, alpha, beta) |
| THREE_BLOCKS_BROKER_URL | Custom broker endpoint URL |
| THREE_BLOCKS_DEBUG | Enable debug logging (1, true, yes) |
| THREE_BLOCKS_USER_NAME | Display name for welcome message |
| THREE_BLOCKS_LOGIN_PRINT_SHELL | Print shell exports in env mode (1) |
| CI | Enable non-interactive mode (1) |
CI/CD Setup
⚠️ pnpm users: The preinstall hook approach is unreliable with pnpm because pnpm resolves packages BEFORE running preinstall scripts. Use the CI Install Override approach below instead.
Recommended: CI Install Override (All CIs)
Run the login command BEFORE pnpm install, not as a preinstall hook:
Vercel
// vercel.json
{
"installCommand": "npx -y three-blocks-login@latest && pnpm install"
}Set THREE_BLOCKS_SECRET_KEY in Vercel → Project Settings → Environment Variables.
AWS Amplify
# amplify.yml
version: 1
frontend:
phases:
preBuild:
commands:
- npx -y three-blocks-login@latest
- pnpm install
build:
commands:
- pnpm buildSet THREE_BLOCKS_SECRET_KEY in Amplify Console → App Settings → Environment Variables.
GitHub Actions
- name: Auth three-blocks
run: npx -y three-blocks-login@latest
env:
THREE_BLOCKS_SECRET_KEY: ${{ secrets.THREE_BLOCKS_SECRET_KEY }}
- name: Install dependencies
run: pnpm installNetlify
# netlify.toml
[build]
command = "npx -y three-blocks-login@latest && pnpm install && pnpm build"Set THREE_BLOCKS_SECRET_KEY in Netlify → Site Settings → Environment Variables.
Generic CI
Always run login before install:
npx -y three-blocks-login@latest && pnpm installAlternative: Preinstall Hook (npm only)
⚠️ This approach only works reliably with npm, not pnpm. For pnpm, use CI Install Override above.
Commit a base
.npmrc(no auth token):@three-blocks:registry=https://three-blocks-196905988268.d.codeartifact.ap-northeast-1.amazonaws.com/npm/core/Add preinstall script:
{ "scripts": { "preinstall": "npx -y three-blocks-login@latest" } }Set
THREE_BLOCKS_SECRET_KEYin CI environment variables.
Troubleshooting
401 Unauthorized on Vercel/Amplify/CI
Problem: Getting ERR_PNPM_FETCH_401 or 401 errors in CI.
Root Cause: pnpm resolves packages BEFORE running preinstall scripts. If you're using a preinstall hook with pnpm, it won't work reliably.
Solution: Use CI Install Override instead of preinstall hooks.
For Vercel, add to vercel.json:
{
"installCommand": "npx -y three-blocks-login@latest && pnpm install"
}For other CIs, see the CI/CD Setup section above.
Also check:
THREE_BLOCKS_SECRET_KEYis set in CI environment variables.npmrcdoes NOT contain an_authTokenline (tokens expire in 12h)- Remove any preinstall hook from
package.jsonif using CI override
License Key Format
License keys must:
- Start with
tb_prefix - Contain at least 10 characters after the prefix
- Only contain characters:
A-Z,a-z,0-9,_,-
Example: tb_AbC123XyZ456...
Token Expiry
Tokens are short-lived (typically 12 hours). If you see 401 errors:
- Check that
THREE_BLOCKS_SECRET_KEYis set correctly - Run the preinstall script manually to test:
npm run preinstallorpnpm preinstall - Verify the broker endpoint is accessible:
curl -I https://www.threejs-blocks.com/api/npm/token
npm Config Warnings
If you see warnings like npm WARN invalid config unknown="...":
- Use
pnpm dlxinstead ofnpx - Or ignore the warnings (they're harmless)
Security
- License keys are validated locally before being sent to the broker
- Tokens are masked in CLI output (
••••{last4}) .npmrcfiles are created with0o600permissions (read/write for owner only)- Sensitive environment variables are scrubbed before running npm commands
What's Safe to Commit?
✅ SAFE - Base .npmrc with registry URL only:
@three-blocks:registry=https://three-blocks-196905988268.d.codeartifact.ap-northeast-1.amazonaws.com/npm/core/❌ NEVER COMMIT - Lines containing auth tokens:
//three-blocks-196905988268.d.codeartifact.ap-northeast-1.amazonaws.com/npm/core/:_authToken=eyJ2...❌ NEVER COMMIT - .env.local with license keys
Add to your .gitignore:
.env.localNote: You can now commit .npmrc safely - the preinstall script merges auth tokens without overwriting your base configuration.
How It Works
- License Key Validation: The CLI validates your license key format locally
- Broker Request: Sends your license key to the broker endpoint via Bearer auth
- Token Exchange: The broker returns a short-lived npm token and registry URL
- npm Configuration: Writes authentication to
.npmrcin the selected mode
License Key → Broker Service → Short-lived NPM Token → CodeArtifact AccessLicense Tiers
The CLI supports multiple license tiers:
- Indie/Core: Access to
@three-blocks/corepackage - Pro: Access to all
@three-blocks/*packages including starter templates
Your tier is determined by your license key and displayed in the CLI output.
Support
For issues or questions:
- Check the troubleshooting guide above
- Review your Vercel environment variables
- Verify your license key format
- Contact Three Blocks support with your license ID (not the full key)
Version
Current version: 0.1.4
For the latest version, always use @latest:
npx -y three-blocks-login@latest