safe-action-better-auth

Integrate Better Auth typed authentication into Next.js server actions.

1|Updated Feb 6, 2026
One-click install
npx skills add https://github.com/gepetojj/umo --skill safe-action-better-auth
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: safe-action-better-auth
Source: https://github.com/gepetojj/umo/tree/main/.agents/skills/safe-action-better-auth
Command: npx skills add https://github.com/gepetojj/umo --skill safe-action-better-auth

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Safe server actions in Next.js often require typed user context and robust authorization. This Skill provides a guided integration of Better Auth with Next.js server actions, enabling secure, typed access control and predictable behavior across actions.

Core Features & Use Cases

  • Typed auth context injected into actions (ctx.auth with user and session)
  • Pre-fetched session data and centralized authorization flows (authorize patterns)
  • Guidance to enable cookies integration (nextCookies) and auth interrupts for reliable server actions

Quick Start

Configure BetterAuth with your auth instance, enable nextCookies() for cookies, enable authInterrupts in Next.js, and use the adapter in server actions to protect authenticated flows.

Frequently Asked Questions about safe-action-better-auth

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

FAQPage Schema
How do I add typed authorization to Next.js server actions?

To add typed authorization to Next.js server actions, inject a typed auth context containing user and session data into your action handlers to enforce secure role checks and access control.

How do I integrate Better Auth with Next.js server actions for session pre-fetching?

Integrate Better Auth by configuring your auth instance to pre-fetch session data and enabling the nextCookies plugin, ensuring authenticated server actions have reliable access to user session context.

Do I need to enable authInterrupts in next.config.ts for safe server actions?

Yes, you need to enable authInterrupts in next.config.ts to allow authentication redirects to interrupt server action execution cleanly, preventing unauthorized operations from proceeding.

What's the best way to handle optional authentication in Next.js safe actions?

The best way to handle optional authentication in safe actions is to pre-fetch session data via Better Auth and conditionally pass the typed auth context, allowing actions to adapt to both guest and authenticated users.

Why are my Better Auth session cookies missing during Next.js server action execution?

Session cookies are likely missing because the nextCookies integration was not enabled, which is required to bridge cookie data into the server action execution context for reliable session retrieval.

Can I enforce role checks using a typed auth context in Next.js safe actions?

Yes, you can enforce role checks by supplying a typed auth context with user and session properties to your safe actions, applying centralized authorization patterns before executing logic.