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

easy.auth98

v6.0.0

Published

EasyAuth SDK - Secure authentication as a service with enterprise self-hosting options

Downloads

45

Readme

EasyAuth SDK

A simple, powerful authentication SDK for developers.

Features

  • Uses EasyAuth server for authentication
  • 🔐 Complete Authentication - Login, register, logout with JWT tokens (Automatically stores and manages tokens)
  • 🌐 OAuth Integration - Google, GitHub, and Facebook OAuth with provider linking
  • 📧 Email Verification - Uses the EasyAuth server's email verification system
  • 🔄 Password Reset - Server-handled forgot password functionality
  • 🏢 Multi-Tenant Support - Same OAuth accounts across different applications
  • 🔗 Provider Linking - Link multiple OAuth providers to a single account
  • 🔒 Production Ready - Built with security and performance in mind
  • 📦 Easy Integration - Just a few lines of code to get started
  • ⚛️ React Hooks - Built-in hooks for easy React integration

Installation

npm install easy.auth98

Please Visit Our Documentation for more details.

Basic Authentication

import { signIn, signUp, signOut, getSession } from 'easy.auth98';

// Simple registration (no email verification)
const registerResult = await signUp('[email protected]', 'password123', 'username');

// Registration with email verification
const registerWithVerification = await signUp(
  '[email protected]', 
  'password123', 
  'username',
  "emailconfig" : {
    sendVerificationEmail: true,
  }
);

// Sign in
const loginResult = await signIn('[email protected]', 'password123');

// Get current session
const session = await getSession();
if (session) {
  console.log('User:', session.user);
}

// Sign out
await signOut();

Email Verification Workflow

When you enable email verification during registration, the server automatically:

  1. Sends a verification email to the user
  2. Blocks login until email is verified
  3. Provides built-in verification pages
import { resendVerificationEmail } from 'easy.auth98';

// User clicks verification link in email → Server handles verification automatically
// Link format: https://easyauth-server.vercel.app/api/v1/verify-email?token=abc123

// If user needs a new verification email:
await resendVerificationEmail('[email protected]');

// The server provides built-in verification pages:
// ✅ Valid token → Shows success page
// ❌ Invalid/expired token → Shows error page with instructions

Note: You typically don't need to call verifyEmail() directly since the server's built-in verification page handles the token verification when users click the email link.

Password Reset

import { forgotPassword, resetPassword } from 'easy.auth98';

// Send reset email
await forgotPassword('[email protected]');

// U just need to call the forgot password method the server automatically sends a reset email with its own reset page and then u can login afterwards 

### OAuth Authentication

EasyAuth supports OAuth authentication with Google, GitHub, and Facebook providers:

```javascript
import { 
  signInWithOAuth, 
  handleOAuthCallback, 
  linkOAuthProvider, 
  unlinkOAuthProvider, 
  getLinkedProviders,
  handleOAuthLinkCallback
} from 'easy.auth98';

// OAuth Sign In
const googleLogin = () => {
  // Redirects to Google OAuth - no return value needed
  signInWithOAuth('google', '/dashboard');
};

const githubLogin = () => {
  signInWithOAuth('github', '/profile');
};

const facebookLogin = () => {
  signInWithOAuth('facebook', '/home');
};

// Handle OAuth callback (in your callback page)
const result = handleOAuthCallback();
if (result.success) {
  console.log(`Authenticated with ${result.provider}`);
  // User is now logged in, redirect or update UI
} else {
  console.error('OAuth failed:', result.message);
}

// Link additional OAuth providers (for authenticated users)
const linkGoogle = () => {
  linkOAuthProvider('google', '/settings');
};

// Get user's linked providers
const { data } = await getLinkedProviders();
console.log('Linked providers:', data.providers);
console.log('Has password:', data.hasPassword);

// Unlink a provider
await unlinkOAuthProvider(providerId);

OAuth in React

import React, { useState, useEffect } from 'react';
import { 
  signInWithOAuth, 
  handleOAuthCallback, 
  getLinkedProviders, 
  linkOAuthProvider, 
  unlinkOAuthProvider 
} from 'easy.auth98';

function OAuthComponent() {
  const [providers, setProviders] = useState([]);

  useEffect(() => {
    // Handle OAuth callback if present
    const result = handleOAuthCallback();
    if (result.success) {
      console.log('OAuth login successful!');
    }

    // Load linked providers for authenticated users
    loadProviders();
  }, []);

  const loadProviders = async () => {
    const result = await getLinkedProviders();
    if (result.success) {
      setProviders(result.data.providers);
    }
  };

  const handleOAuthLogin = (provider) => {
    signInWithOAuth(provider, '/dashboard');
  };

  const handleLinkProvider = (provider) => {
    linkOAuthProvider(provider, '/settings');
  };

  const handleUnlinkProvider = async (providerId) => {
    await unlinkOAuthProvider(providerId);
    loadProviders(); // Refresh list
  };

  return (
    <div>
      {/* OAuth Login Buttons */}
      <div>
        <h3>Login with OAuth</h3>
        <button onClick={() => handleOAuthLogin('google')}>
          Login with Google
        </button>
        <button onClick={() => handleOAuthLogin('github')}>
          Login with GitHub
        </button>
        <button onClick={() => handleOAuthLogin('facebook')}>
          Login with Facebook
        </button>
      </div>

      {/* Linked Providers Management (for authenticated users) */}
      <div>
        <h3>Linked Accounts</h3>
        {providers.map(provider => (
          <div key={provider.id}>
            <span>{provider.provider.toUpperCase()}</span>
            <button onClick={() => handleUnlinkProvider(provider.id)}>
              Unlink
            </button>
          </div>
        ))}
        
        <h4>Link Additional Accounts</h4>
        <button onClick={() => handleLinkProvider('google')}>Link Google</button>
        <button onClick={() => handleLinkProvider('github')}>Link GitHub</button>
        <button onClick={() => handleLinkProvider('facebook')}>Link Facebook</button>
      </div>
    </div>
  );
}

OAuth Configuration

import { configure } from 'easy.auth98';

// Configure SDK with custom settings
configure({
  baseURL: 'https://your-auth-server.com/api/v1',
  timeout: 15000,
  tokenCookies: {
    access: 'custom_access_token',
    refresh: 'custom_refresh_token'
  },
  tokenExpiry: {
    access: 30 * 60, // 30 minutes
    refresh: 14 * 24 * 60 * 60 // 14 days
  }
});

Multi-Tenant OAuth

The system supports multi-tenant OAuth, allowing the same OAuth account to be used across different applications:

// App 1: todoapp.com
signInWithOAuth('google'); // Uses [email protected]

// App 2: blogapp.com  
signInWithOAuth('google'); // Same [email protected], different user record

React Integration

Using Hooks

import React from 'react';
import { useAuth, useSession } from 'easy.auth98';

function App() {
  const { user, isAuthenticated, isLoading } = useAuth();
  const { data: session, status } = useSession();

  if (isLoading) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      {isAuthenticated ? (
        <div>
          <h1>Welcome, {user.username}!</h1>
          <p>Email: {user.email}</p>
          <p>Role: {user.role}</p>
        </div>
      ) : (
        <div>
          <h1>Please log in</h1>
        </div>
      )}
    </div>
  );
}

export default App;

Session Event Listener

import { events } from 'easy.auth98';

// Listen for session changes
const unsubscribe = events.on('session', (session, status) => {
  console.log('Session changed:', { session, status });
});

// Clean up listener
unsubscribe();

Configuration

// No configuration needed - uses hosted EasyAuth service
import { signIn, signUp } from 'easy.auth98';

Authentication Functions

| Function | Parameters | Returns | Description | |----------|------------|---------|-------------| | signUp | email, password, username, emailConfig? | Promise<Result> | Register a new user | | signIn | email, password | Promise<Result> | Authenticate user | | signOut | None | Promise<Result> | Log out current user | | getSession | None | Promise<Session \| null> | Get current session | | verifyToken | None | Promise<Result> | Verify current token |

OAuth Functions

| Function | Parameters | Returns | Description | |----------|------------|---------|-------------| | signInWithOAuth | provider, redirectPath?, applicationUrl? | Promise<Result> | Initiate OAuth login | | handleOAuthCallback | None | Result | Handle OAuth callback | | linkOAuthProvider | provider, redirectPath? | Promise<Result> | Link OAuth provider to account | | unlinkOAuthProvider | providerId | Promise<Result> | Unlink OAuth provider | | getLinkedProviders | None | Promise<Result> | Get user's linked providers | | handleOAuthLinkCallback | None | Result | Handle OAuth linking callback |

Email Functions

| Function | Parameters | Returns | Description | |----------|------------|---------|-------------| | resendVerificationEmail | email | Promise<Result> | Resend verification email | | forgotPassword | email | Promise<Result> | Send password reset email |

Utility Functions

| Function | Parameters | Returns | Description | |----------|------------|---------|-------------| | isAuthenticated | None | boolean | Check if user has valid tokens | | refreshToken | None | Promise<Result> | Manually refresh access token | | getUser | None | User \| null | Get current user details | | getConfig | None | Config | Get current configuration | | debugTokens | None | TokenDebugInfo | Get token debug information |

React Hooks

| Hook | Returns | Description | |------|---------|-------------| | useAuth | { user, isAuthenticated, isLoading, isUnauthenticated } | Authentication state | | useSession | { data, status, update } | Session management |

Error Types

Authentication Errors

  • LOGIN_FAILED - Invalid credentials
  • REGISTRATION_FAILED - Registration failed
  • VERIFICATION_FAILED - Email verification failed
  • RESET_PASSWORD_FAILED - Password reset failed
  • TOKEN_REFRESH_FAILED - Token refresh failed
  • NETWORK_ERROR - Network connection issues
  • VALIDATION_ERROR - Input validation errors

OAuth Errors

  • OAUTH_INITIATION_ERROR - Failed to start OAuth flow
  • OAUTH_ERROR - OAuth provider error
  • OAUTH_LINK_ERROR - Failed to link OAuth provider
  • CALLBACK_PARSE_ERROR - Failed to parse OAuth callback
  • NO_TOKEN - No token in OAuth callback
  • NOT_BROWSER_ENVIRONMENT - OAuth requires browser
  • FETCH_PROVIDERS_FAILED - Failed to get linked providers
  • UNLINK_FAILED - Failed to unlink provider
  • PROVIDER_NOT_FOUND - OAuth provider not found
  • INVALID_REDIRECT_URL - Invalid or unauthorized redirect URL

Security Features

  • 🔒 Secure HTTP-only cookies for token storage
  • 🔄 Automatic token refresh
  • 🛡️ CSRF protection via SameSite cookies
  • ⏰ Configurable token expiration
  • 🔐 Secure password validation
  • 📧 Email domain validation
  • 🚫 Disposable email blocking

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the ISC License.

Support

For support, email easyauth98@gmail.com or create an issue on GitHub.