From 8613f3e490e06cd2b0efd5a21851533d4a69ad05 Mon Sep 17 00:00:00 2001 From: Marsel Shaikhin Date: Tue, 30 Sep 2025 16:49:45 +0200 Subject: [PATCH 1/2] docs: add documentation about AuthJS adapters --- docs/guide/authjs/nuxt-auth-handler.md | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/guide/authjs/nuxt-auth-handler.md b/docs/guide/authjs/nuxt-auth-handler.md index 053e33dd..ccf27b47 100644 --- a/docs/guide/authjs/nuxt-auth-handler.md +++ b/docs/guide/authjs/nuxt-auth-handler.md @@ -97,6 +97,45 @@ Some uses-cases for each callback could be: You can read more on each of these callbacks, what data they provide and what return value they expect on the offical [NextAuth docs](https://next-auth.js.org/configuration/callbacks). +## Adapters + +By default AuthJS only uses JWT tokens to handle authentication and does not save this data anywhere else. To persist user sessions, accounts, and related data, you can use [AuthJS adapters](https://next-auth.js.org/adapters), i.e. modules that implement a database interface. NuxtAuth is adapter-agnostic and you can use both the official and the custom adapters. + +```ts +import { PrismaAdapter } from '@sidebase/authjs-prisma-adapter' +import { prismaClient } from './your-prisma-client' + +export default NuxtAuthHandler({ + adapter: PrismaAdapter(prismaClient), +}) +``` + +### Install correct official adapters + +When installing official adapters, please use `@next-auth` scoped packages as they are made for `next-auth@4`, in contrast to `@auth` scoped packages made for `authjs@5`. + +### Install Sidebase adapter for Prisma 6 + +The official [`@next-auth/prisma-adapter`](https://www.npmjs.com/package/@next-auth/prisma-adapter) assumes a fixed import path from `@prisma/client`. However, starting from Prisma 6 you can now [specify a custom client output path](https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path) which breaks compatibility with AuthJS as it cannot import the correct client anymore. + +For this purpose NuxtAuth provides a custom adapter implementation which does not import anything from `@prisma`. You can find it [here](https://github.com/sidebase/authjs-prisma-adapter) and install it using: + +::: code-group + +```bash [npm] +npm install @sidebase/authjs-prisma-adapter +``` + +```bash [pnpm] +pnpm install @sidebase/authjs-prisma-adapter +``` + +```bash [yarn] +yarn add @sidebase/authjs-prisma-adapter +``` + +::: + ## Events Events are asynchronous callback functions invoked during certain actions in the authentication flow. They can be used to log certain events or debug your authentication flow. From 76b7cbeafd28578c16841f0bc8f654127b375e02 Mon Sep 17 00:00:00 2001 From: Marsel Shaikhin Date: Tue, 30 Sep 2025 17:29:13 +0200 Subject: [PATCH 2/2] docs: add example for the official adapter package --- docs/guide/authjs/nuxt-auth-handler.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/guide/authjs/nuxt-auth-handler.md b/docs/guide/authjs/nuxt-auth-handler.md index ccf27b47..9483ae21 100644 --- a/docs/guide/authjs/nuxt-auth-handler.md +++ b/docs/guide/authjs/nuxt-auth-handler.md @@ -114,6 +114,11 @@ export default NuxtAuthHandler({ When installing official adapters, please use `@next-auth` scoped packages as they are made for `next-auth@4`, in contrast to `@auth` scoped packages made for `authjs@5`. +```diff +-npm i @auth/prisma-adapter ++npm i @next-auth/prisma-adapter +``` + ### Install Sidebase adapter for Prisma 6 The official [`@next-auth/prisma-adapter`](https://www.npmjs.com/package/@next-auth/prisma-adapter) assumes a fixed import path from `@prisma/client`. However, starting from Prisma 6 you can now [specify a custom client output path](https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path) which breaks compatibility with AuthJS as it cannot import the correct client anymore.