NextAuthClient - Deprecated Client for NextAuth

1.5.0 · deprecated · verified Wed Apr 22

The `next-auth-client` package served as a client-side library for the `next-auth` authentication module, primarily intended for use with `next-auth` versions prior to 1.5.0. Its purpose was to provide utility functions and client-side integration points for managing user sessions and authentication flows within applications leveraging the `next-auth` backend. The current stable version of this specific client library is 1.5.0. However, as of `next-auth` version 1.5.0, the core functionality of `next-auth-client` was absorbed directly into the main `next-auth` package itself, rendering this standalone client library redundant and unmaintained. Consequently, it has no active release cadence and developers are strongly advised against using it for any new or existing projects, and should instead opt for the client utilities bundled directly with `next-auth` (i.e., `import { NextAuth } from 'next-auth/client'`). Its key differentiator was being a separate, lightweight client, but this distinction no longer exists.

Warnings

Install

Imports

Quickstart

Demonstrates the historical client-side usage of the `NextAuth` object from this deprecated package to retrieve session information.

// WARNING: This package is deprecated and should not be used in new projects.
// Its functionality has been integrated directly into the 'next-auth' package.
//
// This quickstart demonstrates the *historical* usage of the next-auth-client package.
//
// In an older client-side application context (e.g., a React component):
import { NextAuth } from 'next-auth-client';

async function checkAuthenticationStatus() {
  try {
    // Attempt to get the session from the next-auth backend via this client.
    // In a real application, this would typically be called on page load
    // or when authentication status needs to be verified.
    const session = await NextAuth.getSession();

    if (session) {
      console.log('User is authenticated.');
      console.log('Session details:', session);
      if (session.user && session.user.email) {
        console.log(`Welcome back, ${session.user.email}!`);
      }
    } else {
      console.log('User is not authenticated.');
      // Example: Redirect to login page in a real app
      // NextAuth.redirect({ url: '/api/auth/signin' });
    }
  } catch (error) {
    console.error('Error checking authentication status:', error);
  }
}

// Simulate calling this function, e.g., on initial application load or component mount
checkAuthenticationStatus();

// Other typical client-side actions (for historical context):
// NextAuth.signin('github'); // Initiates OAuth sign-in
// NextAuth.signout();      // Initiates sign-out
// const csrfToken = await NextAuth.getCsrfToken(); // Fetches CSRF token for forms

view raw JSON →