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

@simple-cinema/passport

v1.0.0

Published

Lightweight SimpleCinema authentication library

Readme

@simple-cinema/passport

A lightweight, stateless authentication library for NestJS applications. It generates and verifies HMAC-signed tokens that encode a user ID and expiry time — no database or session store required.


How it works

A token has four dot-separated parts:

<userPart>.<iatPart>.<expPart>.<mac>

| Part | Content | |------------|-------------------------------------------------| | userPart | Base64URL-encoded user ID | | iatPart | Base64URL-encoded issued-at timestamp (seconds) | | expPart | Base64URL-encoded expiry timestamp (seconds) | | mac | HMAC-SHA256 hex digest of the above three parts |

The HMAC is computed with a domain prefix (PassportTokenAuth/v1) to prevent cross-context reuse. MAC comparison uses timingSafeEqual to prevent timing attacks.


Installation

npm install @simple-cinema/passport
# or
yarn add @simple-cinema/passport

Registration

Synchronous

Use when the secret key is available at module load time (e.g. from a static config).

import { PassportModule } from '@simple-cinema/passport';

@Module({
  imports: [
    PassportModule.register({
      secretKey: 'your-secret-key',
    }),
  ],
})
export class AppModule {}

Asynchronous

Use when the secret key must be resolved from another provider (e.g. a config service).

import { PassportModule } from '@simple-cinema/passport';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    PassportModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        secretKey: config.get<string>('AUTH_SECRET'),
      }),
    }),
  ],
})
export class AppModule {}

PassportModule is decorated with @Global(), so you only need to register it once in your root module. PassportService is automatically available everywhere.


API

PassportService

Inject it anywhere in your application:

import { PassportService } from '@simple-cinema/passport';

@Injectable()
export class AuthService {
  constructor(private readonly passport: PassportService) {}
}

generate(userId: string, ttl: number): string

Creates a signed token for the given user.

| Parameter | Type | Description | |-----------|----------|------------------------------------------| | userId | string | The user identifier to embed in the token | | ttl | number | Time-to-live in seconds |

// Generate a token valid for 1 hour
const token = this.passport.generate('user-123', 3600);

verify(token: string): VerifyResult

Validates a token's signature and expiry.

const result = this.passport.verify(token);

if (result.valid) {
  console.log(result.userId); // 'user-123'
} else {
  console.log(result.reason); // 'Expired' | 'Invalid signature' | 'Invalid format' | 'Error'
}

Return type — VerifyResult:

interface VerifyResult {
  valid: boolean;
  reason?: string;  // present when valid is false
  userId?: string;  // present when valid is true
}

Interfaces

PassportOptions

interface PassportOptions {
  secretKey: string; // HMAC signing key — keep this secret
}

PassportAsyncOptions

interface PassportAsyncOptions {
  imports?: ModuleMetadata['imports'];
  useFactory: (...args: any[]) => PassportOptions | Promise<PassportOptions>;
  inject?: FactoryProvider['inject'];
}

Full example

// auth.module.ts
@Module({
  imports: [
    PassportModule.register({ secretKey: process.env.AUTH_SECRET! }),
  ],
  providers: [AuthService],
})
export class AuthModule {}

// auth.service.ts
@Injectable()
export class AuthService {
  constructor(private readonly passport: PassportService) {}

  login(userId: string) {
    return { token: this.passport.generate(userId, 86400) }; // 24 h
  }

  authenticate(token: string) {
    const result = this.passport.verify(token);
    if (!result.valid) throw new UnauthorizedException(result.reason);
    return result.userId;
  }
}