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

@hawk-hhg/auth-client

v1.2.2

Published

A companion JS library that allows you to connect to your backend service with ease

Readme

TypeScript Auth Client

A TypeScript library for seamless integration with the HAWK Auth client. This frontend library provides authentication, authorization, and user management capabilities for browser-based applications.

Installation

npm install @hawk-hhg/auth-client

Basic Setup

import {HawkAuthClient} from '@hawk-hhg/auth-client';

const client = new HawkAuthClient({
    // The endpoint URL of your auth API
    // If omitted, the client will use the current page URL
    endpointUrl: 'https://your-app.com/auth-api'
});

Core Features

Authentication

The authentication system provides a comprehensive solution for managing user sessions in your frontend application. It handles the complete OAuth flow, token management, and authenticated API requests.

The system automatically manages token refresh cycles and provides a clean interface for making authenticated HTTP requests. The auth.fetch() method works just like the native fetch API but automatically includes authentication headers and handles token refresh when needed.

// Initialize authentication
const auth = await client.getAuth();

// Check authentication status
if (await auth.isAuthenticated()) {
    // User is logged in
}

// Login
await client.login();

// Logout
await client.logout();

// Get current token
const token = auth.getToken();

// Refresh token
await auth.refreshToken();

// Make authenticated requests
const response = await auth.fetch('/api/data');

Event System

The event system enables reactive programming patterns by allowing your application to respond to authentication state changes. This is particularly useful for updating UI components when the user logs in or out, or when implementing single-page applications that need to maintain authentication state.

The system provides events for login and logout operations, making it easy to integrate with any frontend framework or vanilla JavaScript application.

client.addEventListener('login', () => {
    console.log('User logged in');
    // Update UI components
    // Fetch user-specific data
    // Initialize protected features
});

client.addEventListener('logout', () => {
    console.log('User logged out');
    // Clear sensitive data
    // Reset UI state
    // Redirect to public area
});

Guard System

The Guard system provides a sophisticated permission checking mechanism that supports role-based access control (RBAC), group hierarchies, and resource-based permissions. This enables fine-grained access control in your frontend application.

You can verify if a user:

  • Has specific roles (e.g., 'admin', 'editor')
  • Belongs to certain groups or their subgroups
  • Has permission to perform specific actions on resources

The Guard system is particularly useful for:

  • Conditionally rendering UI elements based on permissions
  • Protecting route access
  • Managing feature availability
  • Controlling resource-specific actions
const guard = auth.getGuard();

// Role-based checks
await guard.hasAnyRole('admin', 'editor');

// Group checks - supports hierarchical group structures
await guard.hasAnyGroup('organization.managers');
await guard.hasAnyOrHasChildOfAny('organization.managers');

// Resource scope validation - check permissions for specific resources
await guard.hasAnyResourceScope('document-123', 'read', 'write');

User & Profile Management

The user management system provides access to both basic user information and detailed profile data. This separation allows for efficient data loading and clear separation of concerns between identity information and profile details.

The system supports:

  • Basic user information (ID, username, etc.)
  • Extended profile data
  • Cached profile access
  • Automatic profile updates
// Get user information
const user = await auth.getUser();

// Get user profile
const profile = await auth.getProfile();

Complete Example

Here's a comprehensive example showing the main features:

import {HawkAuthClient} from '@hawk-hhg/auth-client';

async function initializeAuth() {
    const client = new HawkAuthClient({
        endpointUrl: '/auth-api'
    });

    // Set up event listeners
    client.addEventListener('login', () => {
        console.log('User logged in');
    });
    client.addEventListener('logout', () => {
        console.log('User logged out');
    });

    // Initialize authentication
    const auth = await client.getAuth();

    if (!(await auth.isAuthenticated())) {
        await client.login();
        return;
    }

    // Get user information
    const user = await auth.getUser();
    console.log('Logged in user:', user);

    // Check permissions
    const guard = auth.getGuard();
    const canRead = await guard.hasAnyResourceScope('documents', 'read');

    if (canRead) {
        // Make authenticated request
        const response = await auth.fetch('/api/documents');
        const documents = await response.json();
        console.log('Documents:', documents);
    }
}

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

HAWK Fakultät Gestaltung
Interaction Design Lab
Renatastraße 11
31134 Hildesheim

Thank you :D