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

@un-dev-suisse/nestjs-auth

v1.0.3

Published

NestJS Auth Service - A simple auth service for NestJS applications

Readme

@un-dev-suisse/nestjs-auth

npm version License: MIT

Un service d'authentification simple et sécurisé pour les applications NestJS, développé par un-dev-suisse.

🚀 Fonctionnalités

  • Guard d'authentification : Protection automatique des routes
  • Décorateur Public : Marquer les routes publiques
  • Gestion des sessions : Validation sécurisée des sessions utilisateur
  • Exceptions personnalisées : Messages d'erreur en français
  • Intégration Stripe : Support pour les clients Stripe
  • Système de rôles et permissions : Gestion fine des accès

📦 Installation

npm install @un-dev-suisse/nestjs-auth

ou avec pnpm :

pnpm add @un-dev-suisse/nestjs-auth

🔧 Configuration

1. Variables d'environnement

Ajoutez ces variables à votre fichier .env :

# Configuration utilisateur par défaut
DEFAULT_USER_ID=your_default_user_id (uuid format)
[email protected]

# Sécurité
SALT_SESSION_ID=your_session_salt_key

2. Import du module

Dans votre app.module.ts :

import { Module } from '@nestjs/common';
import { AuthModule } from '@un-dev-suisse/nestjs-auth';

@Module({
  imports: [
    AuthModule,
    // ... autres modules
  ],
})
export class AppModule {}

3. Configuration globale du guard

Dans votre main.ts :

import { APP_GUARD } from '@nestjs/core';
import { AuthGuard } from '@un-dev-suisse/nestjs-auth';

@Module({
  providers: [
    {
      provide: APP_GUARD,
      useClass: AuthGuard,
    },
  ],
})
export class AppModule {}

🛡️ Utilisation

Protection des routes

Par défaut, toutes les routes sont protégées. Pour marquer une route comme publique, utilisez le décorateur @Public() :

import { Controller, Get } from '@nestjs/common';
import { Public } from '@un-dev-suisse/nestjs-auth';

@Controller('auth')
export class AuthController {
  
  @Get('login')
  @Public() // Cette route est publique
  login() {
    return { message: 'Page de connexion' };
  }

  @Get('profile')
  // Cette route est protégée par défaut
  getProfile() {
    return { message: 'Profil utilisateur' };
  }
}

Structure des données utilisateur

Le guard s'attend à recevoir les informations utilisateur dans les headers de la requête :

// Headers attendus
{
  'user_infos': JSON.stringify({
    user: {
      id: 'user_id',
      email: '[email protected]'
    },
    session: {
      id: 'session_id'
    },
    roles: ['admin', 'user'],
    permissions: {
      'read': 'posts',
      'write': 'posts'
    },
    stripe: {
      customerId: 'cus_stripe_id'
    },
    hashSessionId: 'hashed_session_id'
  })
}

🔐 Sécurité

Validation des sessions

Le guard valide automatiquement :

  • La présence d'une session active
  • L'intégrité de la session via HMAC-SHA384
  • L'authentification de l'utilisateur

Exceptions personnalisées

Le module fournit des exceptions spécifiques :

  • YouMustBeLoggedInException : Utilisateur non connecté
  • ExpiredSessionException : Session expirée
  • InvalidSessionException : Session invalide

📋 Interfaces TypeScript

IJwtPayload

interface IJwtPayload {
  id: string;
  datas: IDatasPayload;
  iat?: number;
  exp?: number;
}

IDatasPayload

interface IDatasPayload {
  id: string;
  email: string;
  sessionId: string;
  roles: string[];
  permissions: {[name: string]: string};
  stripe: {
    id: string;
    customerId: string;
  };
}

🧪 Tests

# Exécuter les tests
npm test

# Tests avec couverture
npm run test:cov

📝 Scripts disponibles

# Build du projet
npm run build

# Préparation pour publication
npm run prepublishOnly

🤝 Contribution

Les contributions sont les bienvenues ! N'hésitez pas à :

  1. Fork le projet
  2. Créer une branche pour votre fonctionnalité (git checkout -b feature/AmazingFeature)
  3. Commit vos changements (git commit -m 'Add some AmazingFeature')
  4. Push vers la branche (git push origin feature/AmazingFeature)
  5. Ouvrir une Pull Request

📄 Licence

Ce projet est sous licence MIT. Voir le fichier LICENSE pour plus de détails.

🐛 Signaler un bug

Si vous rencontrez un bug, veuillez créer une issue sur GitHub.

📞 Support

Pour toute question ou support, contactez-nous via GitHub Issues.


Développé avec ❤️ par un-dev-suisse