Skip to content

Commit b955bea

Browse files
authored
docs: add documentation about AuthJS adapters (#1059)
* docs: add documentation about AuthJS adapters * docs: add example for the official adapter package
1 parent 6f78e75 commit b955bea

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/guide/authjs/nuxt-auth-handler.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,50 @@ Some uses-cases for each callback could be:
9797

9898
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).
9999

100+
## Adapters
101+
102+
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.
103+
104+
```ts
105+
import { PrismaAdapter } from '@sidebase/authjs-prisma-adapter'
106+
import { prismaClient } from './your-prisma-client'
107+
108+
export default NuxtAuthHandler({
109+
adapter: PrismaAdapter(prismaClient),
110+
})
111+
```
112+
113+
### Install correct official adapters
114+
115+
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`.
116+
117+
```diff
118+
-npm i @auth/prisma-adapter
119+
+npm i @next-auth/prisma-adapter
120+
```
121+
122+
### Install Sidebase adapter for Prisma 6
123+
124+
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.
125+
126+
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:
127+
128+
::: code-group
129+
130+
```bash [npm]
131+
npm install @sidebase/authjs-prisma-adapter
132+
```
133+
134+
```bash [pnpm]
135+
pnpm install @sidebase/authjs-prisma-adapter
136+
```
137+
138+
```bash [yarn]
139+
yarn add @sidebase/authjs-prisma-adapter
140+
```
141+
142+
:::
143+
100144
## Events
101145

102146
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.

0 commit comments

Comments
 (0)