-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce @auth/neon-adapter (#12295)
Co-authored-by: Nico Domino <[email protected]>
- Loading branch information
1 parent
590f01e
commit 35215f8
Showing
13 changed files
with
743 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import { Code } from "@/components/Code" | ||
|
||
<img align="right" src="/img/adapters/neon.svg" height="64" width="64" /> | ||
|
||
# Neon Adapter | ||
|
||
## Resources | ||
|
||
- [Neon documentation](https://neon.tech/docs/) | ||
|
||
## Setup | ||
|
||
### Installation | ||
|
||
```bash npm2yarn | ||
npm install @auth/neon-adapter @neondatabase/serverless | ||
``` | ||
|
||
### Environment Variables | ||
|
||
```sh | ||
DATABASE_URL= | ||
``` | ||
|
||
### Configuration | ||
|
||
<Code> | ||
<Code.Next> | ||
|
||
```ts filename="./auth.ts" | ||
import NextAuth from "next-auth" | ||
import NeonAdapter from "@auth/neon-adapter" | ||
import { Pool } from "@neondatabase/serverless" | ||
|
||
// *DO NOT* create a `Pool` here, outside the request handler. | ||
|
||
export const { handlers, auth, signIn, signOut } = NextAuth(() => { | ||
// Create a `Pool` inside the request handler. | ||
const pool = new Pool({ connectionString: process.env.DATABASE_URL }) | ||
return { | ||
adapter: NeonAdapter(pool), | ||
providers: [], | ||
} | ||
}) | ||
``` | ||
|
||
</Code.Next> | ||
<Code.Qwik> | ||
|
||
```ts filename="/src/routes/[email protected]" | ||
import { QwikAuth$ } from "@auth/qwik" | ||
import NeonAdapter from "@auth/neon-adapter" | ||
import { Pool } from "@neondatabase/serverless" | ||
|
||
// *DO NOT* create a `Pool` here, outside the request handler. | ||
|
||
export const { onRequest, useSession, useSignIn, useSignOut } = QwikAuth$( | ||
() => { | ||
// Create a `Pool` inside the request handler. | ||
const pool = new Pool({ connectionString: process.env.DATABASE_URL }) | ||
return { | ||
adapter: NeonAdapter(pool), | ||
providers: [], | ||
} | ||
} | ||
) | ||
``` | ||
|
||
</Code.Qwik> | ||
<Code.Svelte> | ||
|
||
```ts filename="./src/auth.ts" | ||
import { SvelteKitAuth } from "@auth/sveltekit" | ||
import NeonAdapter from "@auth/neon-adapter" | ||
import { Pool } from "@neondatabase/serverless" | ||
|
||
// *DO NOT* create a `Pool` here, outside the request handler. | ||
|
||
export const { handle, signIn, signOut } = SvelteKitAuth(() => { | ||
// Create a `Pool` inside the request handler. | ||
const pool = new Pool({ connectionString: process.env.DATABASE_URL }) | ||
return { | ||
adapter: NeonAdapter(pool), | ||
providers: [], | ||
} | ||
}) | ||
``` | ||
|
||
</Code.Svelte> | ||
<Code.Express> | ||
|
||
```ts filename="./src/routes/auth.route.ts" | ||
import { ExpressAuth } from "@auth/express" | ||
import NeonAdapter from "@auth/neon-adapter" | ||
import { Pool } from "@neondatabase/serverless" | ||
|
||
const pool = new Pool({ connectionString: process.env.DATABASE_URL }) | ||
|
||
const app = express() | ||
|
||
app.set("trust proxy", true) | ||
app.use( | ||
"/auth/*", | ||
ExpressAuth({ | ||
providers: [], | ||
adapter: NeonAdapter(pool), | ||
}) | ||
) | ||
``` | ||
|
||
</Code.Express> | ||
</Code> | ||
|
||
### Schema | ||
|
||
The SQL schema for the tables used by this adapter is as follows. Learn more about the models at our | ||
doc page on [Database Models](/guides/creating-a-database-adapter). | ||
|
||
```sql | ||
CREATE TABLE verification_token | ||
( | ||
identifier TEXT NOT NULL, | ||
expires TIMESTAMPTZ NOT NULL, | ||
token TEXT NOT NULL, | ||
|
||
PRIMARY KEY (identifier, token) | ||
); | ||
|
||
CREATE TABLE accounts | ||
( | ||
id SERIAL, | ||
"userId" INTEGER NOT NULL, | ||
type VARCHAR(255) NOT NULL, | ||
provider VARCHAR(255) NOT NULL, | ||
"providerAccountId" VARCHAR(255) NOT NULL, | ||
refresh_token TEXT, | ||
access_token TEXT, | ||
expires_at BIGINT, | ||
id_token TEXT, | ||
scope TEXT, | ||
session_state TEXT, | ||
token_type TEXT, | ||
|
||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE sessions | ||
( | ||
id SERIAL, | ||
"userId" INTEGER NOT NULL, | ||
expires TIMESTAMPTZ NOT NULL, | ||
"sessionToken" VARCHAR(255) NOT NULL, | ||
|
||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE users | ||
( | ||
id SERIAL, | ||
name VARCHAR(255), | ||
email VARCHAR(255), | ||
"emailVerified" TIMESTAMPTZ, | ||
image TEXT, | ||
|
||
PRIMARY KEY (id) | ||
); | ||
|
||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<p align="center"> | ||
<br/> | ||
<a href="https://authjs.dev" target="_blank"> | ||
<img height="64px" src="https://authjs.dev/img/logo-sm.png" /> | ||
</a> | ||
<a href="https://neon.tech/" target="_blank"> | ||
<img height="64px" src="https://neon.tech/brand/neon-logo-dark-color.svg" /> | ||
</a> | ||
<h3 align="center"><b>Neon Adapter</b> - NextAuth.js / Auth.js</a></h3> | ||
<p align="center" style="align: center;"> | ||
<a href="https://npm.im/@auth/neon-adapter"> | ||
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" /> | ||
</a> | ||
<a href="https://npm.im/@auth/neon-adapter"> | ||
<img alt="npm" src="https://img.shields.io/npm/v/@auth/neon-adapter?color=green&label=@auth/neon-adapter&style=flat-square"> | ||
</a> | ||
<a href="https://www.npmtrends.com/@auth/neon-adapter"> | ||
<img src="https://img.shields.io/npm/dm/@auth/neon-adapter?label=%20downloads&style=flat-square" alt="Downloads" /> | ||
</a> | ||
<a href="https://github.com/nextauthjs/next-auth/stargazers"> | ||
<img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="GitHub Stars" /> | ||
</a> | ||
</p> | ||
</p> | ||
|
||
--- | ||
|
||
Check out the documentation at [authjs.dev](https://authjs.dev/reference/adapter/pg). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@auth/neon-adapter", | ||
"version": "1.7.4", | ||
"description": "Neon Postgres adapter for next-auth.", | ||
"homepage": "https://authjs.dev", | ||
"repository": "https://github.com/nextauthjs/next-auth", | ||
"bugs": { | ||
"url": "https://github.com/nextauthjs/next-auth/issues" | ||
}, | ||
"author": "Jake Coppinger", | ||
"contributors": [ | ||
"Thang Huu Vu <[email protected]>" | ||
], | ||
"license": "ISC", | ||
"keywords": [ | ||
"next-auth", | ||
"@auth", | ||
"Auth.js", | ||
"next.js", | ||
"oauth", | ||
"postgres" | ||
], | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./index.d.ts", | ||
"import": "./index.js" | ||
} | ||
}, | ||
"files": [ | ||
"*.d.ts*", | ||
"*.js", | ||
"src" | ||
], | ||
"private": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"test": "./test/test.sh", | ||
"build": "tsc", | ||
"clean": "rm -rf *.js *.d.ts*" | ||
}, | ||
"dependencies": { | ||
"@auth/core": "workspace:*", | ||
"@neondatabase/serverless": "^0.10.4" | ||
}, | ||
"devDependencies": { | ||
"@types/ws": "^8.5.13", | ||
"ws": "^8.18.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
\set ON_ERROR_STOP true | ||
|
||
CREATE TABLE verification_token | ||
( | ||
identifier TEXT NOT NULL, | ||
expires TIMESTAMPTZ NOT NULL, | ||
token TEXT NOT NULL, | ||
|
||
PRIMARY KEY (identifier, token) | ||
); | ||
|
||
CREATE TABLE accounts | ||
( | ||
id SERIAL, | ||
"userId" INTEGER NOT NULL, | ||
type VARCHAR(255) NOT NULL, | ||
provider VARCHAR(255) NOT NULL, | ||
"providerAccountId" VARCHAR(255) NOT NULL, | ||
refresh_token TEXT, | ||
access_token TEXT, | ||
expires_at INTEGER, | ||
id_token TEXT, | ||
scope TEXT, | ||
session_state TEXT, | ||
token_type TEXT, | ||
|
||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE sessions | ||
( | ||
id SERIAL, | ||
"userId" INTEGER NOT NULL, | ||
expires TIMESTAMPTZ NOT NULL, | ||
"sessionToken" VARCHAR(255) NOT NULL, | ||
|
||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE users | ||
( | ||
id SERIAL, | ||
name VARCHAR(255), | ||
email VARCHAR(255) UNIQUE, | ||
"emailVerified" TIMESTAMPTZ, | ||
image TEXT, | ||
|
||
PRIMARY KEY (id) | ||
); |
Oops, something went wrong.