auth

Enforce role-based authorization across Next.js and tRPC routes with Better Auth roles.

Updated May 7, 2026
One-click install
npx skills add https://github.com/johinsDev/loyalty-app --skill auth-johinsdev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: auth
Source: https://github.com/johinsDev/loyalty-app/tree/main/.claude/skills/auth
Command: npx skills add https://github.com/johinsDev/loyalty-app --skill auth-johinsdev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Role-based authorization is missing or inconsistent when new routes or tRPC/Next handlers are added, which can accidentally expose staff or owner functionality to the wrong users.

Core Features & Use Cases

  • Consistent role model: Defines the canonical roles (customer, staff, manager, owner) and how they map to sign-in surfaces across the web PWA and admin.
  • Defense-in-depth authorization: Guides you to choose the right guard layer (proxy redirect, Server Component role checks, tRPC procedure role enforcement, or Next /api handler role enforcement) instead of relying on a single check.
  • Safe, repeatable onboarding: Explains how to seed the first owner so dev-only routes remain protected until explicitly configured.

Quick Start

When you add a new protected admin page or tRPC mutation, select the appropriate guard (layout requireRole plus the matching staffProcedure/managerProcedure/ownerProcedure) and never rely on proxy.ts alone.

Frequently Asked Questions about auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement role-based access control in a Next.js and tRPC monorepo?

Role-based access control in a Next.js and tRPC monorepo is enforced by layering proxy redirects, Server Component role checks, and matching tRPC procedures like staffProcedure or ownerProcedure to prevent unauthorized access.

What is the best way to protect Next.js API routes using Better Auth organization roles?

Protecting Next.js API routes with Better Auth involves applying the requireApiRole function to enforce organization membership roles, ensuring correct handling of session presence versus validity for admin and API endpoints.

Can I rely on proxy.ts alone for route authorization in a Next.js admin application?

Relying on proxy.ts alone for route authorization is insufficient. A defense-in-depth approach is required, combining layout requireRole checks with matching tRPC procedures to secure staff and owner functionality.

How do I safely bootstrap the first owner during database seeding for a multi-tenant application?

Bootstrapping the first owner in a multi-tenant application requires using a dedicated seed script to safely assign the owner role, ensuring dev-only routes remain protected until explicitly configured.

Why are my tRPC mutations exposing staff functionality to standard customers?

tRPC mutations expose staff functionality when missing or inconsistent role checks are applied. You must select the appropriate guard layer, such as managerProcedure or ownerProcedure, rather than relying on a single proxy check.