Socket
Book a DemoInstallSign in
Socket

local-authority

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

local-authority

A comprehensive user management and authorization package for Node.js applications

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Local Authority

Eine umfassende Benutzer- und Authentifizierungsverwaltung für Node.js-Anwendungen.

Installation

npm install local-authority

Schnellstart

1. Initialisierung

import { AuthService, AuthMiddleware, RoleService } from 'local-authority';

// Initialisiere die Services
const authService = new AuthService('dein-geheimer-schlüssel');
const roleService = new RoleService();
const authMiddleware = new AuthMiddleware(authService, roleService);

2. Routen schützen

import express from 'express';
const app = express();

// Authentifizierung für eine Route
app.get('/geschuetzt', 
  authMiddleware.authenticate, 
  (req, res) => {
    res.json({ message: 'Geschützter Bereich' });
  }
);

// Autorisierung mit Rollen
app.post('/admin', 
  authMiddleware.authenticate,
  authMiddleware.requireRoles(['admin']),
  (req, res) => {
    res.json({ message: 'Admin-Bereich' });
  }
);

// Feingranulare Berechtigungen
app.put('/benutzer/:id', 
  authMiddleware.authenticate,
  authMiddleware.authorize('user', 'update'),
  (req, res) => {
    res.json({ message: 'Benutzer aktualisiert' });
  }
);

3. Benutzer registrieren und einloggen

// Benutzer registrieren
app.post('/registrieren', async (req, res) => {
  try {
    const { username, email, password } = req.body;
    const user = await authService.register(username, email, password);
    res.json(user);
  } catch (error) {
    res.status(400).json({ message: error.message });
  }
});

// Benutzer einloggen
app.post('/login', async (req, res) => {
  try {
    const { email, password } = req.body;
    const { user, token } = await authService.login(email, password);
    res.json({ user, token });
  } catch (error) {
    res.status(401).json({ message: error.message });
  }
});

Sicherheitshinweise

  • Bewahren Sie Ihren geheimen Schlüssel sicher auf
  • Verwenden Sie HTTPS in Produktionsumgebungen
  • Setzen Sie sichere Password-Hashing-Methoden ein (bereits integriert)
  • Implementieren Sie Rate-Limiting für Login-Versuche

Features

  • Benutzerregistrierung und -authentifizierung
  • JWT-basierte Token-Verwaltung
  • Rollenbasierte Zugriffskontrolle (RBAC)
  • Feingranulare Berechtigungen
  • Express Middleware für Routenschutz
  • TypeScript-Unterstützung

Entwicklung

# Repository klonen
git clone [repository-url]

# Abhängigkeiten installieren
npm install

# Tests ausführen
npm test

# Build erstellen
npm run build

Lizenz

MIT

Keywords

authentication

FAQs

Package last updated on 06 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts