npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

directus-auth-manager

v1.1.0

Published

CLI tool and library for managing multiple Directus credential sets

Downloads

295

Readme

Directus Auth Manager

A CLI tool and library for managing multiple Directus credential sets. Use it standalone to manage credentials, or import it as a dependency in your own CLI tools.

Installation

As a CLI tool

npm install -g directus-auth-manager

As a dependency

npm install directus-auth-manager

CLI Usage

Run the CLI to open the interactive menu:

directus-auth

Interactive Menu

Use the arrow keys to navigate and Enter to select:

  Directus Auth Manager

  Active: production (https://directus.example.com)

? What would you like to do? (Use arrow keys)
❯ ➕  Add credentials
  📋  List all credentials
  🔄  Switch active credentials
  👁️   View current credentials
  ✅  Validate specific credentials
  ✅  Validate all credentials
  🗑️   Remove credentials
  ──────────────
  🚪  Exit

JSON Output

Get active credentials as JSON for scripting:

directus-auth --json
# {"name":"production","url":"https://directus.example.com","token":"your-token"}

# Use with jq
directus-auth --json | jq -r '.url'
directus-auth --json | jq -r '.token'

Library Usage

Import and use in your own CLI tools:

promptForCredentials()

The main function - prompts the user to select saved credentials or enter them manually.

import { promptForCredentials } from 'directus-auth-manager';

// Basic usage - shows list of saved credentials + manual entry option
const creds = await promptForCredentials();
console.log(creds.url, creds.token);

// With options
const creds = await promptForCredentials({
  message: 'Select Directus instance:',    // Custom prompt message
  allowManual: true,                        // Allow manual entry (default: true)
  saveManual: true,                         // Offer to save manual entries (default: true)
  useActiveIfAvailable: true,               // Skip prompt if active credentials exist
});

Returns:

interface CredentialSelection {
  name: string;      // Credential name (e.g., "production")
  url: string;       // Directus server URL
  token: string;     // Access token
  source: 'saved' | 'manual';  // Where the credentials came from
}

getActive()

Get active credentials with a confirmation prompt (returns null if none set or user declines).

import { getActive } from 'directus-auth-manager';

// Shows confirmation prompt (default):
//   Active Directus Credentials
//   Name:   production
//   Server: https://directus.example.com
//   ? Use these credentials? (Y/n)

const creds = await getActive();
if (creds) {
  console.log(`Using ${creds.name}: ${creds.url}`);
} else {
  console.log('No active credentials or user declined');
}

// Skip confirmation prompt
const creds = await getActive({ skipConfirmation: true });

getByName()

Get specific credentials by name.

import { getByName } from 'directus-auth-manager';

const prod = getByName('production');
if (prod) {
  console.log(prod.url, prod.token);
}

listSaved()

Get list of all saved credential names.

import { listSaved } from 'directus-auth-manager';

const names = listSaved();
console.log('Saved credentials:', names);
// ['production', 'staging', 'local']

getActiveDirectusClient()

Get a fully configured Directus SDK client using the active credentials.

import { getActiveDirectusClient } from 'directus-auth-manager';
import { readItems } from '@directus/sdk';

// Define your schema for type safety
interface MySchema {
  posts: { id: string; title: string; content: string }[];
  users: { id: string; email: string }[];
}

const client = getActiveDirectusClient<MySchema>();

if (client) {
  const posts = await client.request(readItems('posts'));
  console.log(posts);
}

validateCredentials()

Validate credentials by calling the Directus API.

import { promptForCredentials, validateCredentials } from 'directus-auth-manager';

const creds = await promptForCredentials();
const result = await validateCredentials(creds.name, { url: creds.url, token: creds.token });

if (result.success) {
  console.log('Valid!', result.user?.email);
} else {
  console.log('Invalid:', result.message);
}

Complete Example

Here's how another CLI might use this library:

#!/usr/bin/env node
import { promptForCredentials, getActive } from 'directus-auth-manager';

async function main() {
  // Try to use active credentials (shows confirmation), prompt if none or declined
  let creds = await getActive();
  
  if (!creds) {
    creds = await promptForCredentials({
      message: 'Select or enter Directus credentials:',
    });
  }
  
  console.log(`\nConnecting to ${creds.url}...`);
  
  // Use the credentials
  const response = await fetch(`${creds.url}/items/posts`, {
    headers: { Authorization: `Bearer ${creds.token}` },
  });
  
  const data = await response.json();
  console.log('Posts:', data);
}

main();

Configuration

Credentials are stored in ~/.config/directus-auth-manager/config.json.

{
  "active": "production",
  "credentials": {
    "production": {
      "url": "https://directus.example.com",
      "token": "your-static-token"
    },
    "staging": {
      "url": "https://staging.directus.example.com",
      "token": "another-token"
    }
  }
}

API Reference

Types

interface Credentials {
  url: string;
  token: string;
}

interface CredentialSelection {
  name: string;
  url: string;
  token: string;
  source: 'saved' | 'manual';
}

interface PromptOptions {
  message?: string;
  allowManual?: boolean;
  saveManual?: boolean;
  useActiveIfAvailable?: boolean;
}

interface GetActiveOptions {
  skipConfirmation?: boolean;  // Skip confirmation prompt (default: false)
}

interface ValidationResult {
  name: string;
  success: boolean;
  message: string;
  user?: { id: string; email: string; first_name?: string; last_name?: string };
}

Functions

| Function | Description | |----------|-------------| | promptForCredentials(options?) | Interactive prompt to select/enter credentials | | getActive(options?) | Get active credentials with confirmation prompt | | getActiveDirectusClient<Schema>() | Get configured Directus SDK client with active credentials | | getByName(name) | Get credentials by name (sync, no prompt) | | listSaved() | List all saved credential names (sync) | | validateCredentials(name, creds) | Validate credentials against Directus API | | validateAllCredentials(credsMap) | Validate multiple credential sets |

Requirements

  • Node.js 18 or higher

License

MIT