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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@quadcore-lib/auth-server

v0.1.3

Published

Módulo NestJS que resuelve autenticación via Auth0 JWT y autorización por roles almacenados en DB propia.

Readme

@quadcore-lib/auth-server

Módulo NestJS que resuelve autenticación via Auth0 JWT y autorización por roles almacenados en DB propia.

Instalación

npm install @quadcore-lib/auth-server

Requisitos

Peer dependencies que la app consumidora debe tener instaladas:

npm install @nestjs/common @nestjs/core @nestjs/typeorm typeorm reflect-metadata

Tu app también necesita TypeOrmModule.forRoot() configurado con una DB que incluya la tabla users.

Uso

1. Registrar el módulo

// app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { QuadcoreAuthModule } from '@quadcore-lib/auth-server';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'postgres',
      url: process.env.DATABASE_URL,
      autoLoadEntities: true,
    }),
    QuadcoreAuthModule.forRoot({
      domain: 'mi-tenant.auth0.com',
      audience: 'https://api.miapp.com',
    }),
  ],
})
export class AppModule {}

2. Proteger rutas con JWT

import { Controller, Get, UseGuards } from '@nestjs/common';
import { JwtAuthGuard, CurrentUser } from '@quadcore-lib/auth-server';

@Controller('perfil')
export class PerfilController {
  @UseGuards(JwtAuthGuard)
  @Get()
  getPerfil(@CurrentUser() user: Record<string, unknown>) {
    return user; // payload del JWT de Auth0
  }
}

3. Restringir por rol

import { Controller, Delete, Param, UseGuards } from '@nestjs/common';
import { JwtAuthGuard, RolesGuard, Roles } from '@quadcore-lib/auth-server';

@Controller('usuarios')
export class UsuariosController {
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('admin')
  @Delete(':id')
  eliminar(@Param('id') id: string) {
    return { eliminado: id };
  }
}

RolesGuard lee el rol desde la tabla users en tu DB, no desde el token.

4. Crear o sincronizar usuarios desde Auth0

import { Injectable } from '@nestjs/common';
import { AuthService } from '@quadcore-lib/auth-server';

@Injectable()
export class OnboardingService {
  constructor(private readonly authService: AuthService) {}

  async sincronizar(auth0Id: string, email: string) {
    return this.authService.findOrCreate(auth0Id, email);
  }
}

API

QuadcoreAuthModule

| Método | Descripción | |---|---| | forRoot(options) | Registra el módulo globalmente con la configuración de Auth0 |

AuthModuleOptions

| Campo | Tipo | Requerido | Descripción | |---|---|---|---| | domain | string | sí | Dominio Auth0, ej: mi-tenant.auth0.com | | audience | string | sí | Audience del API en Auth0 | | roleField | string | no | Reservado para uso futuro |

Guards

| Export | Tipo | Descripción | |---|---|---| | JwtAuthGuard | Guard | Valida el JWT de Auth0 via JWKS. Rechaza con 401 si el token es inválido o expiró | | RolesGuard | Guard | Verifica el rol del usuario contra la DB. Usar siempre junto a JwtAuthGuard |

Decoradores

| Export | Uso | Descripción | |---|---|---| | @CurrentUser() | Param decorator | Inyecta el payload del JWT en el parámetro del handler | | @Roles(...roles) | Method/Class decorator | Define los roles requeridos para acceder al endpoint |

Servicios

| Export | Método | Descripción | |---|---|---| | AuthService | findOrCreate(auth0Id, email) | Busca o crea el usuario en DB | | AuthService | findByAuth0Id(auth0Id) | Devuelve el usuario por su ID de Auth0 o null |

Entidades

| Export | Tabla | Columnas | |---|---|---| | UserEntity | users | id (uuid), email, role (default: "user"), auth0Id, createdAt, updatedAt |

Flujo de autenticación

Request → JwtAuthGuard
            ↓ GET https://{domain}/.well-known/jwks.json
            ↓ valida firma RS256 + audience + issuer
            ↓ setea request.user = payload del JWT
         RolesGuard (si se usa)
            ↓ lee user.sub del payload
            ↓ consulta SELECT * FROM users WHERE auth0Id = sub
            ↓ compara user.role con @Roles(...)
         Handler