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 🙏

© 2025 – Pkg Stats / Ryan Hefner

authrix-sdk

v1.1.6

Published

Authrix - The only authentication SDK you'll ever need for your React applications.

Readme

Authrix Authentication SDK

Authentication SDK with React hooks, automatic token refresh, and comprehensive error handling.

Features

  • 🔐 Complete authentication flow (login, register, logout, password reset)
  • 🔄 Automatic token refresh with retry logic
  • 🛡️ Built-in rate limiting and request retry
  • ⚛️ React hooks for seamless integration
  • 🍪 Secure cookie-based token storage
  • 📝 Comprehensive TypeScript support
  • 🔍 Configurable logging system

Installation

npm install authrix-sdk
# or
yarn add authrix-sdk
# or
bun install authrix-sdk

Quick Start

1. Initialize the Client

import { AuthClient, AuthProvider } from 'authrix-sdk';

const authClient = new AuthClient({
  apiKey: 'your-api-key',
  baseUrl: 'https://your-api-url.com'
});

// Wrap your app with AuthProvider
function App() {
  return (
    <AuthProvider client={authClient}>
      <YourApp />
    </AuthProvider>
  );
}

2. Use Authentication Hooks

import { useAuth } from 'authrix-sdk';

function LoginComponent() {
  const { login, register, user, loading, logout } = useAuth();
  
  const handleLogin = async () => {
    try {
      await login({ 
        email: '[email protected]', 
        password: 'password' 
      });
    } catch (error) {
      console.error('Login failed:', error);
    }
  };
  
  const handleRegister = async () => {
    try {
      await register({
        email: '[email protected]',
        password: 'password',
        username: 'username'
      });
    } catch (error) {
      console.error('Registration failed:', error);
    }
  };
  
  if (loading) return <div>Loading...</div>;
  
  return (
    <div>
      {user ? (
        <div>
          <p>Welcome, {user.username || user.email}!</p>
          <button onClick={logout}>Logout</button>
        </div>
      ) : (
        <div>
          <button onClick={handleLogin}>Login</button>
          <button onClick={handleRegister}>Register</button>
        </div>
      )}
    </div>
  );
}

API Reference

AuthClient

const client = new AuthClient({
  apiKey: 'your-api-key',
  baseUrl: 'https://your-api-url.com', // optional, defaults to localhost:3000
  timeout: 10000, // optional, request timeout in ms
  retries: 3 // optional, number of retries for failed requests
});

useAuth Hook

const {
  user,           // Current user object or null
  loading,        // Loading state
  login,          // Login function
  register,       // Register function  
  logout,         // Logout function
  logoutAll,      // Logout from all devices
  isAuthenticated // Boolean authentication status
} = useAuth();

Methods

login(credentials)

await login({
  email: '[email protected]',
  password: 'password'
});

register(userData)

await register({
  email: '[email protected]',
  password: 'password',
  username: 'username'
});

logout()

await logout(); // Logout from current device

logoutAll()

await logoutAll(); // Logout from all devices

Password Reset

// Request password reset (server will send email with code)
await client.requestPasswordReset('[email protected]');

// Reset password with code from email
await client.resetPassword('123456', 'newPassword');

Configuration

interface AuthConfig {
  apiKey: string;        // Your application API key
  baseUrl?: string;      // API base URL (optional)
  timeout?: number;      // Request timeout in milliseconds (optional)
  retries?: number;      // Number of retries for failed requests (optional)
}

Error Handling

The SDK throws descriptive errors that you can catch and handle:

try {
  await login({ email: '[email protected]', password: 'wrong' });
} catch (error) {
  if (error.message.includes('Invalid credentials')) {
    // Handle invalid login
  } else if (error.message.includes('verify')) {
    // Handle email verification required
  }
}

TypeScript Support

The SDK is written in TypeScript and includes full type definitions:

import type { User, AuthResponse, LoginData, RegisterData } from 'authrix-sdk';

License

MIT