feat: introduce @auth/supabase-adapter (#7807)

Database adapters are not dependent on Next.js features, so it makes sense to republish them under the `@auth/*` scope.

This PR is part of a series to convert adapters, using `@auth/core` for types.

If you are coming from the previous adapter, change your `package.json`:

```diff
-  "@next-auth/supabase-adapter": "0.0.0",
+  "@auth/supabase-adapter": "0.0.0",
```

And run `npm install`, `yarn install` or `pnpm install` respectively.

**Note:** This packages is published as ESM-only
This commit is contained in:
Balázs Orbán
2023-06-14 14:09:29 +02:00
committed by GitHub
parent 662e0942cb
commit 06a7149b66
13 changed files with 182 additions and 178 deletions

View File

@@ -31,7 +31,7 @@ body:
- "@auth/pouchdb-adapter"
- "@auth/prisma-adapter"
- "@auth/sequelize-adapter"
- "@next-auth/supabase-adapter"
- "@auth/supabase-adapter"
- "@auth/typeorm-adapter"
- "@auth/upstash-redis-adapter"
- "@auth/xata-adapter"

View File

@@ -31,7 +31,7 @@ sequelize:
- "@auth/sequelize-adapter"
supabase:
- "@next-auth/supabase-adapter"
- "@auth/supabase-adapter"
typeorm:
- "@auth/typeorm-adapter"

View File

@@ -16,7 +16,7 @@
"dependencies": {
"@auth/fauna-adapter": "workspace:*",
"@auth/prisma-adapter": "workspace:*",
"@next-auth/supabase-adapter": "workspace:*",
"@auth/supabase-adapter": "workspace:*",
"@auth/typeorm-adapter": "workspace:*",
"@prisma/client": "^3",
"@supabase/supabase-js": "^2.0.5",

View File

@@ -60,7 +60,7 @@ import WorkOS from "next-auth/providers/workos"
// })
// // Supabase
// import { SupabaseAdapter } from "@next-auth/supabase-adapter"
// import { SupabaseAdapter } from "@auth/supabase-adapter"
// const adapter = SupabaseAdapter({
// url: process.env.NEXT_PUBLIC_SUPABASE_URL,
// secret: process.env.SUPABASE_SERVICE_ROLE_KEY,

View File

@@ -17,7 +17,7 @@
"@auth/core": "workspace:*",
"@auth/fauna-adapter": "workspace:*",
"@auth/prisma-adapter": "workspace:*",
"@next-auth/supabase-adapter": "workspace:*",
"@auth/supabase-adapter": "workspace:*",
"@auth/typeorm-adapter": "workspace:*",
"@prisma/client": "^3",
"@supabase/supabase-js": "^2.0.5",

View File

@@ -64,7 +64,7 @@ import WorkOS from "@auth/core/providers/workos"
// })
// // Supabase
// import { SupabaseAdapter } from "@next-auth/supabase-adapter"
// import { SupabaseAdapter } from "@auth/supabase-adapter"
// const adapter = SupabaseAdapter({
// url: process.env.NEXT_PUBLIC_SUPABASE_URL,
// secret: process.env.SUPABASE_SERVICE_ROLE_KEY,

View File

@@ -8,14 +8,14 @@
</a>
<h3 align="center"><b>Supabase Adapter</b> - NextAuth.js / Auth.js</a></h3>
<p align="center" style="align: center;">
<a href="https://npm.im/@next-auth/supabase-adapter">
<a href="https://npm.im/@auth/supabase-adapter">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@next-auth/supabase-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@next-auth/supabase-adapter?color=green&label=@next-auth/supabase-adapter&style=flat-square">
<a href="https://npm.im/@auth/supabase-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/supabase-adapter?color=green&label=@auth/supabase-adapter&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@next-auth/supabase-adapter">
<img src="https://img.shields.io/npm/dm/@next-auth/supabase-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
<a href="https://www.npmtrends.com/@auth/supabase-adapter">
<img src="https://img.shields.io/npm/dm/@auth/supabase-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" />

View File

@@ -1,14 +1,26 @@
{
"name": "@next-auth/supabase-adapter",
"version": "0.2.1",
"description": "Supabase adapter for next-auth.",
"name": "@auth/supabase-adapter",
"version": "0.0.0",
"description": "Supabase adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
"bugs": {
"url": "https://github.com/nextauthjs/next-auth/issues"
},
"author": "Martin Sonnberger <martin.sonnberger@icloud.com>",
"main": "dist/index.js",
"type": "module",
"types": "./index.d.ts",
"files": [
"*.js",
"*.d.ts*",
"src"
],
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
},
"keywords": [
"next-auth",
"next.js",
@@ -23,16 +35,17 @@
"build": "tsc",
"test": "./tests/test.sh"
},
"dependencies": {
"@auth/core": "workspace:*"
},
"peerDependencies": {
"@supabase/supabase-js": "^2.0.5",
"next-auth": "^4.18.7"
"@supabase/supabase-js": "^2.0.5"
},
"devDependencies": {
"@next-auth/adapter-test": "workspace:^0.0.0",
"@next-auth/tsconfig": "workspace:^0.0.0",
"@supabase/supabase-js": "^2.0.5",
"jest": "^27.4.3",
"next-auth": "workspace:*"
"jest": "^27.4.3"
},
"jest": {
"preset": "@next-auth/adapter-test/jest"

View File

@@ -1,139 +0,0 @@
export type Json =
| string
| number
| boolean
| null
| { [key: string]: Json }
| Json[]
export interface Database {
next_auth: {
Tables: {
accounts: {
Row: {
id: string
type: string | null
provider: string | null
providerAccountId: string | null
refresh_token: string | null
access_token: string | null
expires_at: number | null
token_type: string | null
scope: string | null
id_token: string | null
session_state: string | null
oauth_token_secret: string | null
oauth_token: string | null
userId: string | null
}
Insert: {
id?: string
type?: string | null
provider?: string | null
providerAccountId?: string | null
refresh_token?: string | null
access_token?: string | null
expires_at?: number | null
token_type?: string | null
scope?: string | null
id_token?: string | null
session_state?: string | null
oauth_token_secret?: string | null
oauth_token?: string | null
userId?: string | null
}
Update: {
id?: string
type?: string | null
provider?: string | null
providerAccountId?: string | null
refresh_token?: string | null
access_token?: string | null
expires_at?: number | null
token_type?: string | null
scope?: string | null
id_token?: string | null
session_state?: string | null
oauth_token_secret?: string | null
oauth_token?: string | null
userId?: string | null
}
}
sessions: {
Row: {
expires: string | null
sessionToken: string | null
userId: string | null
id: string
}
Insert: {
expires?: string | null
sessionToken?: string | null
userId?: string | null
id?: string
}
Update: {
expires?: string | null
sessionToken?: string | null
userId?: string | null
id?: string
}
}
users: {
Row: {
name: string | null
email: string | null
emailVerified: string | null
image: string | null
id: string
}
Insert: {
name?: string | null
email?: string | null
emailVerified?: string | null
image?: string | null
id?: string
}
Update: {
name?: string | null
email?: string | null
emailVerified?: string | null
image?: string | null
id?: string
}
}
verification_tokens: {
Row: {
id: number
identifier: string | null
token: string | null
expires: string | null
}
Insert: {
id?: number
identifier?: string | null
token?: string | null
expires?: string | null
}
Update: {
id?: number
identifier?: string | null
token?: string | null
expires?: string | null
}
}
}
Views: {
[_ in never]: never
}
Functions: {
uid: {
Args: Record<PropertyKey, never>
Returns: string
}
}
Enums: {
[_ in never]: never
}
}
}

View File

@@ -9,19 +9,18 @@
* ## Installation
*
* ```bash npm2yarn2pnpm
* npm install @supabase/supabase-js next-auth @next-auth/supabase-adapter
* npm install @supabase/supabase-js @auth/supabase-adapter
* ```
*
* @module @next-auth/supabase-adapter
* @module @auth/supabase-adapter
*/
import { createClient } from "@supabase/supabase-js"
import { Database } from "./database.types"
import {
Adapter,
AdapterSession,
AdapterUser,
VerificationToken,
} from "next-auth/adapters"
} from "@auth/core/adapters"
function isDate(date: any) {
return (
@@ -61,7 +60,7 @@ export interface SupabaseAdapterOptions {
* :::note
* This adapter is developed by the community and not officially maintained or supported by Supabase. It uses the Supabase Database to store user and session data in a separate `next_auth` schema. It is a standalone Auth server that does not interface with Supabase Auth and therefore provides a different feature set.
*
* If youre looking for an officially maintained Auth server with additional features like [built-in email server](https://supabase.com/docs/guides/auth/auth-email#configure-email-settings?utm_source=authjs-docs&medium=referral&campaign=authjs), [phone auth](https://supabase.com/docs/guides/auth/auth-twilio?utm_source=authjs-docs&medium=referral&campaign=authjs), and [Multi Factor Authentication (MFA / 2FA)](https://supabase.com/contact/mfa?utm_source=authjs-docs&medium=referral&campaign=authjs), please use [Supabase Auth](https://supabase.com/auth) with the [Auth Helpers for Next.js](https://supabase.com/docs/guides/auth/auth-helpers/nextjs?utm_source=authjs-docs&medium=referral&campaign=authjs).
* If you're looking for an officially maintained Auth server with additional features like [built-in email server](https://supabase.com/docs/guides/auth/auth-email#configure-email-settings?utm_source=authjs-docs&medium=referral&campaign=authjs), [phone auth](https://supabase.com/docs/guides/auth/auth-twilio?utm_source=authjs-docs&medium=referral&campaign=authjs), and [Multi Factor Authentication (MFA / 2FA)](https://supabase.com/contact/mfa?utm_source=authjs-docs&medium=referral&campaign=authjs), please use [Supabase Auth](https://supabase.com/auth) with the [Auth Helpers for Next.js](https://supabase.com/docs/guides/auth/auth-helpers/nextjs?utm_source=authjs-docs&medium=referral&campaign=authjs).
* :::
*
* ## Setup
@@ -72,7 +71,7 @@ export interface SupabaseAdapterOptions {
*
* ```js title="pages/api/auth/[...nextauth].js"
* import NextAuth from "next-auth"
* import { SupabaseAdapter } from "@next-auth/supabase-adapter"
* import { SupabaseAdapter } from "@auth/supabase-adapter"
*
* // For more information on each option (and a full list of options) go to
* // https://authjs.dev/reference/configuration/auth-config
@@ -224,7 +223,7 @@ export interface SupabaseAdapterOptions {
*
* ```js title="pages/api/auth/[...nextauth].js"
* import NextAuth from "next-auth"
* import { SupabaseAdapter } from "@next-auth/supabase-adapter"
* import { SupabaseAdapter } from "@auth/supabase-adapter"
* import jwt from "jsonwebtoken"
*
* // For more information on each option (and a full list of options) go to
@@ -350,9 +349,7 @@ export function SupabaseAdapter(options: SupabaseAdapterOptions): Adapter {
const { url, secret } = options
const supabase = createClient<Database, "next_auth">(url, secret, {
db: { schema: "next_auth" },
global: {
headers: { "X-Client-Info": "@next-auth/supabase-adapter@0.1.0" },
},
global: { headers: { "X-Client-Info": "@auth/supabase-adapter" } },
})
return {
async createUser(user) {
@@ -524,3 +521,135 @@ export function SupabaseAdapter(options: SupabaseAdapterOptions): Adapter {
},
}
}
interface Database {
next_auth: {
Tables: {
accounts: {
Row: {
id: string
type: string | null
provider: string | null
providerAccountId: string | null
refresh_token: string | null
access_token: string | null
expires_at: number | null
token_type: string | null
scope: string | null
id_token: string | null
session_state: string | null
oauth_token_secret: string | null
oauth_token: string | null
userId: string | null
}
Insert: {
id?: string
type?: string | null
provider?: string | null
providerAccountId?: string | null
refresh_token?: string | null
access_token?: string | null
expires_at?: number | null
token_type?: string | null
scope?: string | null
id_token?: string | null
session_state?: string | null
oauth_token_secret?: string | null
oauth_token?: string | null
userId?: string | null
}
Update: {
id?: string
type?: string | null
provider?: string | null
providerAccountId?: string | null
refresh_token?: string | null
access_token?: string | null
expires_at?: number | null
token_type?: string | null
scope?: string | null
id_token?: string | null
session_state?: string | null
oauth_token_secret?: string | null
oauth_token?: string | null
userId?: string | null
}
}
sessions: {
Row: {
expires: string | null
sessionToken: string | null
userId: string | null
id: string
}
Insert: {
expires?: string | null
sessionToken?: string | null
userId?: string | null
id?: string
}
Update: {
expires?: string | null
sessionToken?: string | null
userId?: string | null
id?: string
}
}
users: {
Row: {
name: string | null
email: string | null
emailVerified: string | null
image: string | null
id: string
}
Insert: {
name?: string | null
email?: string | null
emailVerified?: string | null
image?: string | null
id?: string
}
Update: {
name?: string | null
email?: string | null
emailVerified?: string | null
image?: string | null
id?: string
}
}
verification_tokens: {
Row: {
id: number
identifier: string | null
token: string | null
expires: string | null
}
Insert: {
id?: number
identifier?: string | null
token?: string | null
expires?: string | null
}
Update: {
id?: number
identifier?: string | null
token?: string | null
expires?: string | null
}
}
}
Views: {
[_ in never]: never
}
Functions: {
uid: {
Args: Record<PropertyKey, never>
Returns: string
}
}
Enums: {
[_ in never]: never
}
}
}

View File

@@ -5,8 +5,8 @@ import type {
AdapterSession,
AdapterUser,
VerificationToken,
} from "next-auth/adapters"
import type { Account } from "next-auth"
} from "@auth/core/adapters"
import type { Account } from "@auth/core/types"
const url = process.env.SUPABASE_URL ?? "http://localhost:54321"
const secret =

13
pnpm-lock.yaml generated
View File

@@ -56,8 +56,8 @@ importers:
'@auth/core': workspace:*
'@auth/fauna-adapter': workspace:*
'@auth/prisma-adapter': workspace:*
'@auth/supabase-adapter': workspace:*
'@auth/typeorm-adapter': workspace:*
'@next-auth/supabase-adapter': workspace:*
'@playwright/test': 1.29.2
'@prisma/client': ^3
'@supabase/supabase-js': ^2.0.5
@@ -80,8 +80,8 @@ importers:
'@auth/core': link:../../../packages/core
'@auth/fauna-adapter': link:../../../packages/adapter-fauna
'@auth/prisma-adapter': link:../../../packages/adapter-prisma
'@auth/supabase-adapter': link:../../../packages/adapter-supabase
'@auth/typeorm-adapter': link:../../../packages/adapter-typeorm
'@next-auth/supabase-adapter': link:../../../packages/adapter-supabase
'@prisma/client': 3.15.2_prisma@3.15.2
'@supabase/supabase-js': 2.0.5
faunadb: 4.6.0
@@ -106,8 +106,8 @@ importers:
specifiers:
'@auth/fauna-adapter': workspace:*
'@auth/prisma-adapter': workspace:*
'@auth/supabase-adapter': workspace:*
'@auth/typeorm-adapter': workspace:*
'@next-auth/supabase-adapter': workspace:*
'@prisma/client': ^3
'@supabase/supabase-js': ^2.0.5
'@types/jsonwebtoken': ^8.5.5
@@ -127,8 +127,8 @@ importers:
dependencies:
'@auth/fauna-adapter': link:../../../packages/adapter-fauna
'@auth/prisma-adapter': link:../../../packages/adapter-prisma
'@auth/supabase-adapter': link:../../../packages/adapter-supabase
'@auth/typeorm-adapter': link:../../../packages/adapter-typeorm
'@next-auth/supabase-adapter': link:../../../packages/adapter-supabase
'@prisma/client': 3.15.2_prisma@3.15.2
'@supabase/supabase-js': 2.0.5
faunadb: 4.6.0
@@ -433,17 +433,18 @@ importers:
packages/adapter-supabase:
specifiers:
'@auth/core': workspace:*
'@next-auth/adapter-test': workspace:^0.0.0
'@next-auth/tsconfig': workspace:^0.0.0
'@supabase/supabase-js': ^2.0.5
jest: ^27.4.3
next-auth: workspace:*
dependencies:
'@auth/core': link:../core
devDependencies:
'@next-auth/adapter-test': link:../adapter-test
'@next-auth/tsconfig': link:../tsconfig
'@supabase/supabase-js': 2.0.5
jest: 27.5.1
next-auth: link:../next-auth
packages/adapter-test:
specifiers:

View File

@@ -64,7 +64,7 @@
"@auth/neo4j-adapter#build",
"@auth/pouchdb-adapter#build",
"@auth/sequelize-adapter#build",
"@next-auth/supabase-adapter#build",
"@auth/supabase-adapter#build",
"@auth/typeorm-adapter#build",
"@auth/upstash-redis-adapter#build",
"@auth/xata-adapter#build",
@@ -87,7 +87,7 @@
"@auth/neo4j-adapter#build",
"@auth/pouchdb-adapter#build",
"@auth/sequelize-adapter#build",
"@next-auth/supabase-adapter#build",
"@auth/supabase-adapter#build",
"@auth/typeorm-adapter#build",
"@auth/upstash-redis-adapter#build",
"@auth/xata-adapter#build",