Skip to content

API keys#362

Merged
yusuftomilola merged 2 commits intoDistinctCodes:mainfrom
Divineifed1:main
Oct 5, 2025
Merged

API keys#362
yusuftomilola merged 2 commits intoDistinctCodes:mainfrom
Divineifed1:main

Conversation

@Divineifed1
Copy link
Contributor

Overview

This PR introduces a new API Keys Module that allows companies to securely generate, manage, and authenticate API keys for integrating with AssetsUp’s backend services.

Key Features

API Key Entity (api_keys table) with fields: id, key, companyId, status, expiryDate, timestamps.

Endpoints for key management:

POST /api-keys → Generate a new API key for a company.

DELETE /api-keys → Revoke (disable) an existing API key.

GET /api-keys/:companyId → List all API keys for a given company.

Service logic for:

Secure random API key generation (crypto.randomBytes)

Validation of active and non-expired keys

Revocation and listing of keys

Middleware (ApiKeyMiddleware) to validate API keys via the x-api-key header for protected routes.

Company relation added to allow each company to own multiple API keys.

Technical Details

Module: ApiKeysModule

Files added:

api-key.entity.ts

dto/create-api-key.dto.ts

dto/revoke-api-key.dto.ts

providers/api-keys.service.ts

api-keys.controller.ts

middleware/api-key.middleware.ts

api-keys.module.ts

Integrated with existing Company entity through TypeORM relations.

@vercel
Copy link

vercel bot commented Oct 5, 2025

@Divineifed1 is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@yusuftomilola yusuftomilola merged commit 737a18d into DistinctCodes:main Oct 5, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants