2024-06-14
5399
#nextjs
Ejiro Asiuwhu
30990
Jun 14, 2024 ⋅ 19 min read

How to use Auth.js for client-side authentication in Next.js

Ejiro Asiuwhu Software engineer with a drive for building highly scalable and performant web applications. Heavily interested in module federation, micro frontends, state machines, TDD, and system designs. Big on web performance and optimization, advanced component design patterns, a11y, SSR, SSG, ISR, and state management. Expert at crafting highly reusable TypeScript-heavy component libraries.

Recent posts:

Effective rendering with Selective SSR in TanStack Start

TanStack Start’s Selective SSR lets you control route rendering with server, client, or data-only modes. Learn how it works with a real app example.

Amazing Enyichi Agu
Aug 14, 2025 ⋅ 10 min read

The deep internals of event delegation: When bubbling isn’t enough

Learn how event delegation works, why it’s efficient, and how to handle pitfalls, non-bubbling events, and framework-specific implementations.

Clara Ekekenta
Aug 14, 2025 ⋅ 10 min read
ai dev tool power rankings

AI dev tool power rankings & comparison [August 2025 edition]

Our August 2025 AI dev tool rankings compare 17 top models and platforms across 40+ features. Use our interactive comparison engine to find the best tool for your needs.

Chizaram Ken
Aug 14, 2025 ⋅ 8 min read

React’s `use()` API is about to make useContext obsolete

Learn how React’s new use() API elevates state management and async data fetching for modern, efficient components.

Emmanuel John
Aug 12, 2025 ⋅ 7 min read
View all posts

14 Replies to "How to use Auth.js for client-side authentication in Next.js"

  1. Really great article 😊 I really enjoyed reading it and it makes me want to switch to Next.js. I was wondering why you called this client-side rather than severless? Is the authentication not done server side by SSR? I really apologize if I’m wrong, I’m just trying to understand the authentication flow.

  2. website: next-auth.js
    Example code : next-auth-example
    npm package : next-auth

    But it is called NextAuth.js and not next-auth.js as one could guess from all your urls.

    Am I missing something here ?

  3. Unhandled Runtime Error
    Error: React Context is unavailable in Server Components

    Call Stack
    SessionProvider

    can you please resolve this error

    1. Use the “use client” flag at the top of the file.
      That error is showing up because “SessionProvider” is using react context which is a client component and for it to work, you must mark the file as a client component with the flag above.

      You are using react 13.+.+ I believe

  4. You are using next-auth v5. However, using app router in next 15, `useSession` cannot be used. I’ve been forced to use `auth()` exported from the @/auth.tsx file. SessionProvider is also not usable any more.

Leave a Reply