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.

Nous respectons votre vie privée

Ce site utilise des cookies pour des analyses anonymes afin d'améliorer votre expérience. Aucune information personnelle n'est stockée ni partagée. Vous pouvez autoriser ou refuser le suivi analytique à tout moment. Consultez notre Politique de Confidentialité.

Nous utilisons des cookies pour des analyses anonymes. Aucune donnée personnelle n'est stockée. Consultez notre Politique de Confidentialité.