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:

Is Better Auth the key to solving authentication headaches?

Better Auth is an open-source, TypeScript-first auth library with adapters, schema generation, and a plugin system. Here’s how it works and how it stacks up to Clerk, NextAuth, and Auth0.

David Omotayo
Sep 26, 2025 ⋅ 10 min read
What using a screen reader taught me about real web accessibility

What using a screen reader taught me about real web accessibility

Read one developer’s detailed account of using a screen reader to learn more about a11y and build more accessible websites.

Sebastian Weber
Sep 25, 2025 ⋅ 29 min read
david turnbull claude code hacks

6 easy ways to level up Claude Code

Walk through six tips and tricks that help you level up Claude Code to move beyond simply entering prompts into a text box.

David Turnbull
Sep 24, 2025 ⋅ 5 min read

Choosing the right React Router v7 mode for your project

React Router v7 is now more than routing. This guide explains its three modes—declarative, data, and framework and how to choose the right one for your app.

Amazing Enyichi Agu
Sep 23, 2025 ⋅ 1 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