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

sessionize-auth

v2.0.0

Published

A flexible session management library for React, Next.js, Angular, and React Native

Readme

🚀 Sessionize Auth v2.0

A powerful, flexible session management library for modern web applications with support for React, Next.js, Angular, and more.

npm version TypeScript License: ISC Build Status

✨ Features

  • 🔐 Multiple Storage Options: localStorage, sessionStorage, cookies, Redis, database
  • Return-to Functionality: Automatic redirection after login with smart session management
  • 🎯 Framework Adapters: Dedicated adapters for React (ready), Next.js (structure), Angular (planned)
  • 🔑 SSO Integration: Single Sign-On with Google, Microsoft, GitHub and custom providers
  • 📱 TypeScript First: Full type safety and excellent developer experience
  • 🔄 Pluggable Architecture: Modular design for maximum flexibility and extensibility
  • 🚀 Lightweight: Minimal dependencies with Zustand for state management
  • 🧪 Well Tested: Comprehensive test coverage with Jest
  • 🎨 Demo Application: Complete working example with modern UI

🚀 Quick Start

Installation

npm install sessionize-auth
# or
yarn add sessionize-auth
# or
pnpm add sessionize-auth

Basic Usage (React)

import { AuthProvider, useAuth, withAuth } from 'sessionize-auth';

// 1. Wrap your app with AuthProvider
function App() {
  return (
    <AuthProvider
      config={{
        storageType: 'localStorage',
        redirectPath: '/login',
        returnToParam: 'returnTo'
      }}
    >
      <YourApp />
    </AuthProvider>
  );
}

// 2. Use the useAuth hook
function Dashboard() {
  const { account, isAuthenticated, login, logout } = useAuth();
  
  if (!isAuthenticated) {
    return <div>Please log in</div>;
  }
  
  return (
    <div>
      <h1>Welcome, {account.name}!</h1>
      <button onClick={logout}>Logout</button>
    </div>
  );
}

// 3. Or use the HOC
const ProtectedDashboard = withAuth()(Dashboard);

SSO Integration

import { AuthProvider, useAuth, SSOManager, SSOProviderList } from 'sessionize-auth';

// Configure SSO providers
const ssoManager = new SSOManager({
  providers: [
    {
      id: 'google',
      name: 'Google',
      clientId: 'your-google-client-id',
      redirectUri: 'http://localhost:3000/auth/callback',
      scopes: ['openid', 'email', 'profile']
    },
    {
      id: 'microsoft',
      name: 'Microsoft',
      clientId: 'your-microsoft-client-id',
      redirectUri: 'http://localhost:3000/auth/callback',
      scopes: ['openid', 'email', 'profile', 'User.Read']
    }
  ]
});

function App() {
  return (
    <AuthProvider config={{ storageType: 'localStorage' }}>
      <YourApp />
    </AuthProvider>
  );
}

// Use SSO in your login component
function LoginPage() {
  const { login } = useAuth();
  const { providers, loginWithProvider } = useSSO(ssoManager);

  const handleSSOLogin = async (providerId: string) => {
    const result = await loginWithProvider(providerId);
    if (result.success && result.user) {
      login(result.user);
    }
  };

  return (
    <div>
      <SSOProviderList 
        providers={providers}
        onProviderLogin={handleSSOLogin}
      />
    </div>
  );
}

Advanced Usage with Custom Stores

import { AuthProvider, useAuth, createMemoryStore } from 'sessionize-auth';

// Custom store for testing or SSR
const memoryStore = createMemoryStore();

function App() {
  return (
    <AuthProvider
      config={{
        storageType: 'localStorage',
        redirectPath: '/login',
        returnToParam: 'returnTo',
        storageKey: 'my_app_session'
      }}
    >
      <YourApp />
    </AuthProvider>
  );
}

📚 Documentation

Core Concepts

Session Store

The session store is responsible for persisting user data across browser sessions.

import { createSessionStore } from 'sessionize-auth';

const store = createSessionStore({
  storageType: 'localStorage', // 'localStorage' | 'sessionStorage' | 'cookies'
  storageKey: 'user_session'
});

// Access session data
const { account, startSession, closeSession } = store.getState();

Return-to Functionality

Automatically redirect users back to their intended destination after login.

// When accessing a protected route, the current URL is automatically saved
// After login, user is redirected back to the original location
const { login } = useAuth();

// Login with optional return-to parameter
login(userData, '/dashboard/settings');

// Or let the system handle it automatically
login(userData); // Will redirect to saved return-to URL

Advanced Configuration

Custom Storage Backend

import { createRedisStore, createMemoryStore } from 'sessionize-auth/stores';

// Redis store (for production)
const redisStore = createRedisStore({
  host: 'localhost',
  port: 6379,
  password: 'your-password',
  ttl: 7 * 24 * 60 * 60 // 7 days
});

// Memory store (for testing)
const memoryStore = createMemoryStore();

Protected Routes with HOC

import { withAuth } from 'sessionize-auth';

// Protect individual components
const ProtectedDashboard = withAuth({
  redirectPath: '/login',
  fallback: LoadingComponent
})(Dashboard);

// Use in your routing
<Route path="/dashboard" element={<ProtectedDashboard />} />

🎯 Framework Adapters

React ✅ Ready

  • useAuth() hook for state management
  • withAuth() HOC for component protection
  • AuthProvider for app-wide configuration
  • Full TypeScript support

Next.js 🚧 Structure Ready

  • Server-side rendering support (planned)
  • Middleware for route protection (planned)
  • Automatic cookie handling (planned)

Angular 📋 Planned

  • Service-based architecture
  • Route guards
  • Dependency injection support

🛠️ Pluggable Stores

  • localStorage ✅: Browser local storage with persistence
  • sessionStorage ✅: Browser session storage (cleared on tab close)
  • cookies ✅: HTTP cookies with security options (secure, sameSite)
  • Redis 🚧: Redis-based session store (structure ready)
  • Database 🚧: SQL/NoSQL database integration (structure ready)
  • Memory ✅: In-memory store for testing and SSR

🔑 SSO Providers

  • Google ✅: OAuth 2.0 with OpenID Connect
  • Microsoft ✅: Azure AD OAuth 2.0 integration
  • GitHub ✅: GitHub OAuth 2.0 authentication
  • Custom ✅: Extensible provider system for any OAuth 2.0 provider

🎨 Demo Application

Experience Sessionize Auth v2.0 with our complete demo application:

# Clone and setup
git clone https://github.com/Katumbela/sessionize-auth.git
cd sessionize-auth

# Install dependencies
npm install

# Run demo
npm run demo:dev

Demo Features:

  • ✅ Complete authentication flow
  • ✅ Protected routes with return-to functionality
  • ✅ SSO integration with Google, Microsoft, GitHub
  • ✅ Modern, responsive UI
  • ✅ TypeScript integration
  • ✅ Multiple storage options

Demo Credentials:

🚀 Getting Started with Demo

Quick Setup

# Option 1: Use the setup script (Windows)
./setup-demo.ps1

# Option 2: Use the setup script (Linux/Mac)
./setup-demo.sh

# Option 3: Manual setup
npm install
cd demo
npm install
npm run dev

Project Structure

sessionize-auth/
├── src/
│   ├── core/                    # Core session management
│   ├── adapters/react/          # React integration
│   ├── stores/                  # Pluggable storage backends
│   └── index.ts                 # Main exports
├── demo/                        # Complete demo application
│   ├── src/
│   │   ├── components/          # Reusable components
│   │   ├── pages/               # Application pages
│   │   └── App.tsx              # Main app component
│   └── README.md                # Demo documentation
└── README.md                    # This file

🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. Report Issues: Found a bug? Open an issue
  2. Suggest Features: Have an idea? Start a discussion
  3. Submit PRs: Want to contribute code? Fork and submit a pull request
  4. Improve Docs: Help us make the documentation better

Development Setup

# Clone the repository
git clone https://github.com/Katumbela/sessionize-auth.git
cd sessionize-auth

# Install dependencies
npm install

# Run tests
npm test

# Build the library
npm run build

# Run demo
npm run demo:dev

📄 License

This project is licensed under the ISC License - see the LICENSE file for details.

🙏 Acknowledgments

  • Built with Zustand for state management
  • Inspired by modern authentication patterns and best practices
  • Community feedback and contributions
  • Special thanks to all contributors and users

📞 Support