Skip to content

Commit 9f358a0

Browse files
k-taro56ndom91
andauthored
chore(docs): Add Neon's Postgres documents for edge runtime (#11129)
chore: Update PostgreSQL adapter in documentation examples Co-authored-by: Nico Domino <[email protected]>
1 parent ec93976 commit 9f358a0

File tree

1 file changed

+40
-0
lines changed
  • docs/pages/getting-started/adapters

1 file changed

+40
-0
lines changed

docs/pages/getting-started/adapters/pg.mdx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
5151
})
5252
```
5353

54+
If you are using [Neon](https://neon.tech)'s PostgreSQL like [Vercel Postgres](https://vercel.com/docs/postgres), you can use `@neondatabase/serverless` to work with edge runtime.
55+
56+
```ts filename="./auth.ts"
57+
import NextAuth from "next-auth"
58+
import PostgresAdapter from "@auth/pg-adapter"
59+
import { Pool } from "@neondatabase/serverless"
60+
61+
// *DO NOT* create a `Pool` here, outside the request handler.
62+
// Neon's Postgres cannot keep a pool alive between requests.
63+
64+
export const { handlers, auth, signIn, signOut } = NextAuth(() => {
65+
// Create a `Pool` inside the request handler.
66+
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
67+
return {
68+
adapter: PostgresAdapter(pool),
69+
providers: [],
70+
}
71+
})
72+
```
73+
5474
</Code.Next>
5575
<Code.Svelte>
5676

@@ -75,6 +95,26 @@ export const { handle, signIn, signOut } = SvelteKitAuth({
7595
})
7696
```
7797

98+
If you are using [Neon](https://neon.tech)'s PostgreSQL like [Vercel Postgres](https://vercel.com/docs/postgres), you can use `@neondatabase/serverless` to work with edge runtime.
99+
100+
```ts filename="./src/auth.ts"
101+
import { SvelteKitAuth } from "@auth/sveltekit"
102+
import PostgresAdapter from "@auth/pg-adapter"
103+
import { Pool } from "@neondatabase/serverless"
104+
105+
// *DO NOT* create a `Pool` here, outside the request handler.
106+
// Neon's Postgres cannot keep a pool alive between requests.
107+
108+
export const { handle, signIn, signOut } = SvelteKitAuth(() => {
109+
// Create a `Pool` inside the request handler.
110+
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
111+
return {
112+
adapter: PostgresAdapter(pool),
113+
providers: [],
114+
}
115+
})
116+
```
117+
78118
</Code.Svelte>
79119
<Code.Express>
80120

0 commit comments

Comments
 (0)