Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(adapter): add postgres.js adapter #10570

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/adapter-pg/README.md
Expand Up @@ -6,16 +6,16 @@
<a href="https://www.postgresql.org/" target="_blank">
<img height="64px" src="https://authjs.dev/img/adapters/pg.png"/>
</a>
<h3 align="center"><b>Postgres Adapter</b> - NextAuth.js / Auth.js</a></h3>
<h3 align="center"><b>PostgresJS Adapter</b> - NextAuth.js / Auth.js</a></h3>
<p align="center" style="align: center;">
<a href="https://npm.im/@auth/pg-adapter">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@auth/pg-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/pg-adapter?color=green&label=@auth/pg-adapter&style=flat-square">
<a href="https://npm.im/@auth/postgresjs-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/postgresjs-adapter?color=green&label=@auth/pg-adapter&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@auth/pg-adapter">
<img src="https://img.shields.io/npm/dm/@auth/pg-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
<img src="https://img.shields.io/npm/dm/@auth/postgresjs-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" />
Expand Down
28 changes: 28 additions & 0 deletions packages/adapter-postgresjs/README.md
@@ -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://www.postgresql.org/" target="_blank">
<img height="64px" src="https://authjs.dev/img/adapters/pg.png"/>
</a>
<h3 align="center"><b>Postgres Adapter</b> - NextAuth.js / Auth.js</a></h3>
<p align="center" style="align: center;">
<a href="https://npm.im/@auth/pg-adapter">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@auth/pg-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/pg-adapter?color=green&label=@auth/pg-adapter&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@auth/pg-adapter">
<img src="https://img.shields.io/npm/dm/@auth/pg-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).
53 changes: 53 additions & 0 deletions packages/adapter-postgresjs/package.json
@@ -0,0 +1,53 @@
{
"name": "@auth/postgresjs-adapter",
"version": "0.1.0",
"description": "PostgresJS 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": [
"Cody Bontecou <codybontecou@gmail.com>"
],
"license": "ISC",
"keywords": [
"next-auth",
"@auth",
"Auth.js",
"next.js",
"oauth",
"postgres.js"
],
"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"
},
"dependencies": {
"@auth/core": "workspace:*"
},
"peerDependencies": {
"pg": "^8"
},
"devDependencies": {
"@types/pg": "^8.6.5",
"pg": "^8.7.1"
}
}
49 changes: 49 additions & 0 deletions packages/adapter-postgresjs/schema.sql
@@ -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 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)
);