JSPM

@skylabs-digital/react-identity-access

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 24
  • Score
    100M100P100Q65902F
  • License MIT

A comprehensive React library for multi-tenancy, authentication, authorization, roles, session management, and settings management

Package Exports

  • @skylabs-digital/react-identity-access

Readme

React Identity Access

A powerful, modern authentication and authorization library for React applications. Built with TypeScript, featuring role-based access control, permission management, and seamless integration with React applications.

๐Ÿš€ Features

  • ๐Ÿ” Secure Authentication - JWT-based authentication with automatic token refresh
  • ๐Ÿ‘ฅ Role-Based Access Control - Granular permission system with role hierarchy
  • ๐Ÿ›ก๏ธ Protected Components - Easy-to-use components for conditional rendering
  • ๐Ÿ“ฑ Multi-Tenant Support - Built-in support for multi-tenant applications
  • ๐ŸŽฏ TypeScript First - Full TypeScript support with comprehensive type definitions
  • โšก Modern React - Built with React hooks and context for optimal performance
  • ๐Ÿ”„ Session Management - Automatic session handling and token refresh
  • ๐ŸŽจ Feature Flags - Built-in feature flag management
  • ๐Ÿ’ณ Subscription Management - Integrated billing and subscription handling

๐Ÿ“ฆ Installation

npm install react-identity-access
# or
yarn add react-identity-access
# or
pnpm add react-identity-access

๐Ÿƒโ€โ™‚๏ธ Quick Start

1. Setup Providers

Wrap your application with the required providers:

import { AppProvider, AuthProvider } from 'react-identity-access';

function App() {
  return (
    <AppProvider
      config={{
        baseUrl: 'https://your-api.com',
        appId: 'your-app-id',
        tenantMode: 'subdomain', // or 'path' or 'header'
        selectorParam: 'tenant',
      }}
    >
      <AuthProvider>
        {/* Your app components */}
      </AuthProvider>
    </AppProvider>
  );
}

2. Use Authentication

import { useAuth } from 'react-identity-access';

function LoginComponent() {
  const { login, logout, sessionManager } = useAuth();
  const user = sessionManager.getUser();

  const handleLogin = async () => {
    try {
      await login('user@example.com', 'password', 'tenant-id');
    } catch (error) {
      console.error('Login failed:', error);
    }
  };

  return (
    <div>
      {user ? (
        <div>
          <p>Welcome, {user.name}!</p>
          <button onClick={logout}>Logout</button>
        </div>
      ) : (
        <button onClick={handleLogin}>Login</button>
      )}
    </div>
  );
}

3. Protect Components

import { Protected } from 'react-identity-access';

function AdminPanel() {
  return (
    <Protected
      requiredPermissions={['admin:read', 'users:manage']}
      fallback={<div>Access denied</div>}
    >
      <div>Admin content here</div>
    </Protected>
  );
}

๐Ÿ—๏ธ Architecture

Core Providers

  • AppProvider - Application configuration and context
  • AuthProvider - Authentication and session management
  • FeatureFlagProvider - Feature flag management
  • SubscriptionProvider - Billing and subscription handling

Permission System

The library uses a resource-action permission format:

resource:action

Examples:

  • users:read - Read user data
  • products:write - Create/update products
  • admin:* - All admin permissions
  • reports:read - View reports

๐Ÿ“š Documentation

๐ŸŽฎ Demo Application

A complete demo application is included in the template/ directory. To run it:

cd template
pnpm install
pnpm start

The demo showcases:

  • User authentication flow
  • Role-based dashboard
  • Permission testing
  • Protected routes
  • Feature flag usage

๐Ÿ› ๏ธ Development

Prerequisites

  • Node.js 16+
  • pnpm (recommended) or npm/yarn

Setup

# Clone the repository
git clone <repository-url>
cd react-identity-access

# Install dependencies
pnpm install

# Build the library
pnpm build

# Run tests
pnpm test

# Start development
pnpm dev

Project Structure

react-identity-access/
โ”œโ”€โ”€ src/                    # Library source code
โ”‚   โ”œโ”€โ”€ components/         # React components
โ”‚   โ”œโ”€โ”€ providers/          # Context providers
โ”‚   โ”œโ”€โ”€ services/           # API services
โ”‚   โ”œโ”€โ”€ types/              # TypeScript definitions
โ”‚   โ””โ”€โ”€ index.ts           # Main export
โ”œโ”€โ”€ template/               # Demo application
โ”œโ”€โ”€ docs/                   # Documentation
โ”œโ”€โ”€ dist/                   # Built library
โ””โ”€โ”€ package.json

๐Ÿ”ง Configuration

Environment Variables

REACT_APP_BASE_URL=https://your-api.com
REACT_APP_ID=your-app-id
REACT_APP_TENANT_MODE=subdomain

AppProvider Config

interface AppConfig {
  baseUrl: string;           // API base URL
  appId: string;            // Application identifier
  tenantMode: 'subdomain' | 'path' | 'header';
  selectorParam: string;    // Tenant selector parameter
  apiTimeout?: number;      // Request timeout (default: 30000)
  retryAttempts?: number;   // Retry attempts (default: 3)
}

๐Ÿงช Testing

The library includes comprehensive tests:

# Run all tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Run tests with coverage
pnpm test:coverage

๐Ÿ“ˆ Performance

  • Tree-shakable - Only import what you need
  • Lazy loading - Components load on demand
  • Optimized re-renders - Minimal React re-renders
  • Caching - Intelligent caching of API responses

๐Ÿ”’ Security

  • JWT tokens with automatic refresh
  • Secure storage of sensitive data
  • CSRF protection built-in
  • Permission validation on both client and server
  • Audit logging for security events

๐ŸŒ Browser Support

  • Chrome 90+
  • Firefox 88+
  • Safari 14+
  • Edge 90+

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

๐Ÿ“ž Support

๐ŸŽฏ Roadmap

  • OAuth 2.0 / OpenID Connect support
  • Multi-factor authentication
  • Advanced audit logging
  • GraphQL integration
  • React Native support
  • SSR/Next.js optimization

Made with โค๏ธ by Skylabs Digital