RegisterLogin
DocsPricing
RegisterLogin
  • Getting Started
  • Introduction
  • Quick Start
  • SDKs
  • React
  • TypeScript
  • Next.js
  • Express
  • NestJS
  • Python
  • API Reference
  • Support and Resources
  • FAQ
  • Contact

Server Authentication

Server-side helpers for authentication in Server Components, Server Actions, and API Routes.


Overview

The server-side authentication module provides functions to access user sessions, protect routes, and manage tokens in server contexts. Functions include initAuthSafe(), getAuth(), requireAuth(), currentUser(), getAccessToken(), hasScope(), and hasScopes(). All functions work seamlessly with React Server Components, Server Actions, and the Next.js caching system.


Basic Usage

import { getAuth, requireAuth } from 'authsafe-nextjs/server';

// In a Server Component
export default async function Dashboard() {
  const auth = await requireAuth();
  return <p>Welcome, {auth.name}</p>;
}

// In a Server Action
async function updateProfile(formData) {
  'use server';
  const auth = await getAuth();
  if (!auth) throw new Error('Unauthorized');
}

Best Practices
  • Use requireAuth() when authentication is mandatory — it throws if not authenticated
  • Use getAuth() when you want to handle unauthenticated state yourself (returns null)
  • Use getAccessToken() for making authenticated API requests to external services

AuthSafe

Product

HighlightFeatureIntegrationPricingFAQ

Company

AboutBlogContact

Developer

DashboardDocumentation

Legal

Terms & ConditionsPrivacyComplianceShippingCancellationAI

© 2026 AuthSafe. All rights reserved.

We value your privacy

This website uses cookies for anonymous analytics to help us improve your experience. No personal information is stored or shared. You can allow or reject analytics tracking at any time. See our Privacy Policy.

We use cookies for anonymous analytics. No personal info is stored. See our Privacy Policy.