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

@authsome/adapter-generic

v0.1.12

Published

Generic adapter for AuthSome UI - works with any auth backend

Readme

@authsome/adapter-generic

Generic adapter for AuthSome UI - works with any custom auth backend.

Installation

pnpm add @authsome/adapter-generic

Usage

import { AuthClient } from '@authsome/ui-core';
import { GenericAdapter } from '@authsome/adapter-generic';

const authClient = new AuthClient({
  provider: new GenericAdapter({
    baseUrl: 'https://api.example.com',
    endpoints: {
      signIn: '/auth/login',
      signUp: '/auth/register',
      signOut: '/auth/logout',
      getCurrentUser: '/auth/me',
      getCurrentSession: '/auth/session',
    },
  }),
});

Configuration

interface GenericAdapterConfig {
  baseUrl: string;
  endpoints: {
    signIn?: string;
    signUp?: string;
    signOut?: string;
    getCurrentUser?: string;
    getCurrentSession?: string;
    refreshSession?: string;
    updateUser?: string;
    changePassword?: string;
    requestPasswordReset?: string;
    confirmPasswordReset?: string;
    oauthSignIn?: string;
    oauthCallback?: string;
    sendMagicLink?: string;
    verifyMagicLink?: string;
    sendPhoneCode?: string;
    verifyPhoneCode?: string;
    setupTwoFactor?: string;
    verifyTwoFactor?: string;
    disableTwoFactor?: string;
    registerPasskey?: string;
    authenticatePasskey?: string;
    listPasskeys?: string;
    deletePasskey?: string;
  };
  transforms?: {
    transformSignInRequest?: (req) => Record<string, unknown>;
    transformSignUpRequest?: (req) => Record<string, unknown>;
    transformAuthResponse?: (res) => AuthResponse;
    transformUser?: (res) => User;
    transformSession?: (res) => Session;
    transformError?: (error) => AuthError;
  };
  headers?: Record<string, string>;
}

Custom Transformers

Transform your API responses to match AuthSome UI format:

const adapter = new GenericAdapter({
  baseUrl: 'https://api.example.com',
  endpoints: {
    signIn: '/login',
    getCurrentUser: '/user/me',
  },
  transforms: {
    // Transform your API's user format
    transformUser: (apiUser) => ({
      id: apiUser.userId,
      email: apiUser.userEmail,
      emailVerified: apiUser.verified,
      createdAt: apiUser.created,
      updatedAt: apiUser.modified,
    }),
    // Transform your API's error format
    transformError: (apiError) => ({
      message: apiError.errorMessage,
      code: apiError.errorCode,
      statusCode: apiError.status,
    }),
  },
});

Custom Headers

Add authentication headers or custom headers:

const adapter = new GenericAdapter({
  baseUrl: 'https://api.example.com',
  endpoints: { /* ... */ },
  headers: {
    'X-API-Key': 'your-api-key',
    'X-Client-Version': '1.0.0',
  },
});

Complete Example

import { AuthClient } from '@authsome/ui-core';
import { GenericAdapter } from '@authsome/adapter-generic';

const adapter = new GenericAdapter({
  baseUrl: process.env.NEXT_PUBLIC_API_URL!,
  endpoints: {
    // Auth
    signIn: '/api/auth/login',
    signUp: '/api/auth/register',
    signOut: '/api/auth/logout',
    
    // User
    getCurrentUser: '/api/user/me',
    updateUser: '/api/user/update',
    
    // Session
    getCurrentSession: '/api/auth/session',
    refreshSession: '/api/auth/refresh',
    
    // Password
    changePassword: '/api/auth/password/change',
    requestPasswordReset: '/api/auth/password/reset/request',
    confirmPasswordReset: '/api/auth/password/reset/confirm',
    
    // OAuth
    oauthSignIn: '/api/auth/oauth/:provider',
    oauthCallback: '/api/auth/oauth/callback',
    
    // Magic Link
    sendMagicLink: '/api/auth/magic-link/send',
    verifyMagicLink: '/api/auth/magic-link/verify',
    
    // 2FA
    setupTwoFactor: '/api/auth/2fa/setup',
    verifyTwoFactor: '/api/auth/2fa/verify',
    disableTwoFactor: '/api/auth/2fa/disable',
  },
  transforms: {
    transformUser: (data: any) => ({
      id: data.user_id,
      email: data.email_address,
      emailVerified: data.email_verified,
      username: data.display_name,
      metadata: data.custom_data,
      createdAt: data.created_at,
      updatedAt: data.updated_at,
    }),
  },
  headers: {
    'Content-Type': 'application/json',
  },
});

const client = new AuthClient({ provider: adapter });

Supported Features

All features are supported if your backend provides the corresponding endpoints:

  • ✅ Email/Password
  • ✅ OAuth (any providers)
  • ✅ Magic Links
  • ✅ Phone Auth
  • ✅ 2FA
  • ✅ Passkeys
  • ✅ Username Auth
  • ✅ Password Reset
  • ✅ User Updates
  • ⚠️ Organizations (optional - requires custom implementation)

Organization Support

Organizations can be supported by adding organization endpoints to your backend and extending the generic adapter:

import { GenericAdapter } from '@authsome/adapter-generic';

class CustomAdapter extends GenericAdapter {
  async getOrganizations() {
    const response = await fetch(`${this.baseUrl}/organizations`, {
      headers: this.headers,
      credentials: 'include',
    });
    return response.json();
  }
  
  async getActiveOrganization() {
    const response = await fetch(`${this.baseUrl}/organizations/active`, {
      headers: this.headers,
      credentials: 'include',
    });
    return response.json();
  }
  
  async setActiveOrganization(orgId: string) {
    await fetch(`${this.baseUrl}/organizations/${orgId}/activate`, {
      method: 'POST',
      headers: this.headers,
      credentials: 'include',
    });
  }
  
  async getOrganizationMemberships() {
    const response = await fetch(`${this.baseUrl}/organizations/memberships`, {
      headers: this.headers,
      credentials: 'include',
    });
    return response.json();
  }
}

Then use your custom adapter:

const adapter = new CustomAdapter({
  baseUrl: 'https://api.example.com',
  endpoints: { /* ... */ },
});

License

MIT