Eclipse
Boilit
BoilitBoilitBeta
Boilerplates

Boilerplate

Fastify with Managed API Key Authentication

Technical Stack
framework

A boilerplate for Fastify applications, showcasing how to implement API key authentication with Knex.js for database storage. This setup enhances security by storing hashed API keys, allowing for controlled access and key expiration management.

Features

  • Stores API keys in a PostgreSQL database using Knex.js.
  • Uses hashed keys for enhanced security.
  • Supports workspace-based and user-based API key management.
  • Implements validation middleware to check API keys against the database.
  • Tracks key usage with last_used_at for monitoring activity.
  • Supports key expiration with expires_at to enforce lifecycle policies.
  • TypeScript support for type-safe development.

Database Schema

CREATE TABLE public.api_keys ( id VARCHAR NOT NULL PRIMARY KEY, workspace_id VARCHAR NOT NULL, user_id VARCHAR NOT NULL, name VARCHAR NOT NULL, identifier VARCHAR NOT NULL, hashed_key VARCHAR NOT NULL UNIQUE, last_used_at TIMESTAMP NULL, expires_at TIMESTAMP NULL, created_at TIMESTAMP DEFAULT now() NOT NULL, updated_at TIMESTAMP DEFAULT now() NOT NULL );

Use Case

Ideal for applications requiring secure API key authentication with database-backed storage. This boilerplate provides a scalable and structured approach for managing API keys, making it suitable for multi-tenant SaaS platforms, internal services, and restricted endpoints. 🚀

Topics

Boilerplate details

  • Last update


    1 month ago
  • Boilerplate age


    1 month ago
Login to download
Ad

Aragon.ai

Turn your selfies into studio-quality headshots in minutes. Save hundreds of dollars and hours of your time.

Visit Aragon.ai