Skip to content
Back to skills

Nextjs Data Access Layer

ASecurity

Secure, reusable data access patterns with DTOs and Taint checks. Use when building a data access layer with DTOs and server-side taint checking in Next.js. (triggers: **/lib/data.ts, **/services/*.ts, **/dal/**, DAL, Data Access Layer, server-only, DTO)

  • 67 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 10, 2026
developmentreactnextjsapidatabasebackendsecurity

Works with

  • cli
  • api

Security analysis

A100/100

Scanned November 10, 2026

npx -y skills add ComeOnOliver/skillshub --skill nextjs-data-access-layer --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Nextjs Data Access Layer?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Nextjs Data Access Layer
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/comeonoliver-nextjs-data-access-layer/badge)](https://www.skillsdirectory.com/skills/comeonoliver-nextjs-data-access-layer)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: nextjs-data-access-layer
description: 'Secure, reusable data access patterns with DTOs and Taint checks. Use when building a data access layer with DTOs and server-side taint checking in Next.js. (triggers: **/lib/data.ts, **/services/*.ts, **/dal/**, DAL, Data Access Layer, server-only, DTO)'
---

# Data Access Layer (DAL)

## **Priority: P1 (HIGH)**

Centralize all data access (Database & External APIs) to ensure consistent security, authorization, and caching.

## Implementation Guidelines

- **Architecture**: Create a **Data Access Layer (DAL)** in a **`services/`** or **`lib/data.ts`** file. Use **`import 'server-only'`** to prevent leaking backend logic to the client bundle.
- **DTOs**: Always transform raw DB/API data into **Data Transfer Objects (DTOs)** before returning to components. This prevents leaking sensitive fields (e.g., `passwordHash`).
- **Security**: Use **`taintObjectReference`** or **`taintUniqueValue`** from the **`experimental_taint`** API to ensure sensitive data never accidentally reaches Client Components.
- **Authorization**: **Colocate auth checks** inside every DAL function. Don't rely on the UI layer to enforce safety. Use **`await auth()`** to verify the user.
- **Caching**: Wrap DAL functions in **`cache()`** from React to deduplicate requests within a single render cycle, preventing redundant DB/API calls.
- **Error Handling**: Throw **standardized errors** (e.g., `NotFoundError`, `UnauthorizedError`) to be caught by **Next.js `error.tsx`** or **`notFound()`**.

## Limitations

- **Client Components**: Cannot import DAL files. Must use Server Actions or Route Handlers as bridges.

## Anti-Patterns

- **No auth checks outside DAL**: Auth verification must live inside DAL functions.
- **No raw ORM instances returned**: Transform to plain DTO objects before returning.
- **No `fetch('localhost/api')` in Server Components**: Call DAL functions directly.
- **No DAL imports in Client Components**: Use Server Actions or Route Handlers as bridges.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.