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: introduce @auth/typeorm-adapter #7706

Merged
merged 8 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/3_bug_adapter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ body:
- "@auth/prisma-adapter"
- "@next-auth/sequelize-adapter"
- "@next-auth/supabase-adapter"
- "@next-auth/typeorm-legacy-adapter"
- "@auth/typeorm-adapter"
- "@next-auth/upstash-redis-adapter"
- "@next-auth/xata-adapter"
validations:
Expand Down
4 changes: 2 additions & 2 deletions .github/issue-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ sequelize:
supabase:
- "@next-auth/supabase-adapter"

typeorm-legacy:
- "@next-auth/typeorm-legacy-adapter"
typeorm:
- "@auth/typeorm-adapter"

upstash-redis:
- "@next-auth/upstash-redis-adapter"
Expand Down
2 changes: 1 addition & 1 deletion .github/pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ solidjs: ["packages/frameworks-solid-start/**/*"]
supabase: ["packages/adapter-supabase/**/*"]
svelte: ["packages/frameworks-sveltekit/**/*"]
test: ["**test**/*"]
typeorm-legacy: ["packages/adapter-typeorm-legacy/**/*"]
typeorm: ["packages/adapter-typeorm/**/*"]
upstash-redis: ["packages/adapter-upstash-redis/**/*"]
xata: ["packages/adapter-xata/**/*"]
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ on:
- "@auth/prisma-adapter"
- "@auth/sequelize-adapter"
- "@auth/supabase-adapter"
- "@auth/typeorm-legacy-adapter"
- "@auth/typeorm-adapter"
- "@auth/upstash-redis-adapter"
- "@auth/xata-adapter"
- "next-auth"
Expand All @@ -52,7 +52,7 @@ on:
- "adapter-prisma"
- "adapter-sequelize"
- "adapter-supabase"
- "adapter-typeorm-legacy"
- "adapter-typeorm"
- "adapter-upstash-redis"
- "adapter-xata"
- "next-auth"
Expand Down
2 changes: 1 addition & 1 deletion apps/dev/nextjs-v4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@next-auth/fauna-adapter": "workspace:*",
"@auth/prisma-adapter": "workspace:*",
"@next-auth/supabase-adapter": "workspace:*",
"@next-auth/typeorm-legacy-adapter": "workspace:*",
"@auth/typeorm-adapter": "workspace:*",
"@prisma/client": "^3",
"@supabase/supabase-js": "^2.0.5",
"faunadb": "^4",
Expand Down
2 changes: 1 addition & 1 deletion apps/dev/nextjs-v4/pages/api/auth-old/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import WorkOS from "next-auth/providers/workos"
// const adapter = FaunaAdapter(client)

// // TypeORM
// import { TypeORMLegacyAdapter } from "@next-auth/typeorm-legacy-adapter"
// import { TypeORMLegacyAdapter } from "@auth/typeorm-adapter"
// const adapter = TypeORMLegacyAdapter({
// type: "sqlite",
// name: "next-auth-test-memory",
Expand Down
2 changes: 1 addition & 1 deletion apps/dev/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@next-auth/fauna-adapter": "workspace:*",
"@auth/prisma-adapter": "workspace:*",
"@next-auth/supabase-adapter": "workspace:*",
"@next-auth/typeorm-legacy-adapter": "workspace:*",
"@auth/typeorm-adapter": "workspace:*",
"@prisma/client": "^3",
"@supabase/supabase-js": "^2.0.5",
"faunadb": "^4",
Expand Down
2 changes: 1 addition & 1 deletion apps/dev/nextjs/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import WorkOS from "@auth/core/providers/workos"
// const adapter = FaunaAdapter(client)

// // TypeORM
// import { TypeORMLegacyAdapter } from "@next-auth/typeorm-legacy-adapter"
// import { TypeORMLegacyAdapter } from "@auth/typeorm-adapter"
// const adapter = TypeORMLegacyAdapter({
// type: "sqlite",
// name: "next-auth-test-memory",
Expand Down
14 changes: 1 addition & 13 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,7 @@ const docusaurusConfig = {
typedocAdapter("Neo4j"),
typedocAdapter("PouchDB"),
typedocAdapter("Prisma"),
[
"docusaurus-plugin-typedoc",
{
...typedocConfig,
id: "typeorm",
plugin: [require.resolve("./typedoc-mdn-links")],
watch: process.env.TYPEDOC_WATCH,
entryPoints: [`../packages/adapter-typeorm-legacy/src/index.ts`],
tsconfig: `../packages/adapter-typeorm-legacy/tsconfig.json`,
out: `reference/adapter/typeorm`,
sidebar: { indexLabel: "TypeORM" },
},
],
typedocAdapter("TypeORM"),
typedocAdapter("Sequelize"),
typedocAdapter("Supabase"),
typedocAdapter("Upstash Redis"),
Expand Down
12 changes: 0 additions & 12 deletions packages/adapter-typeorm-legacy/tsconfig.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
</a>
<h3 align="center"><b>TypeORM Adapter</b> - NextAuth.js / Auth.js</a></h3>
<p align="center" style="align: center;">
<a href="https://npm.im/@next-auth/typeorm-legacy-adapter">
<a href="https://npm.im/@auth/typeorm-adapter">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@next-auth/typeorm-legacy-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@next-auth/typeorm-legacy-adapter?color=green&label=@next-auth/typeorm-legacy-adapter&style=flat-square">
<a href="https://npm.im/@auth/typeorm-adapter">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/typeorm-adapter?color=green&label=@auth/typeorm-adapter&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@next-auth/typeorm-legacy-adapter">
<img src="https://img.shields.io/npm/dm/@next-auth/typeorm-legacy-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
<a href="https://www.npmtrends.com/@auth/typeorm-adapter">
<img src="https://img.shields.io/npm/dm/@auth/typeorm-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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@next-auth/typeorm-legacy-adapter",
"version": "2.0.2",
"description": "TypeORM (legacy) adapter for next-auth.",
"homepage": "https://authjs.dev",
"name": "@auth/typeorm-adapter",
"version": "0.0.0",
"description": "TypeORM adapter for Auth.js.",
"homepage": "https://authjs.dev/reference/adapter/typeorm",
"repository": "https://github.com/nextauthjs/next-auth",
"bugs": {
"url": "https://github.com/nextauthjs/next-auth/issues"
Expand All @@ -11,11 +11,19 @@
"contributors": [
"Balázs Orbán <info@balazsorban.com>"
],
"main": "dist/index.js",
"type": "module",
"types": "./index.d.ts",
"files": [
"README.md",
"dist"
"*.js",
"*.d.ts*",
"src"
],
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
},
"license": "ISC",
"keywords": [
"next-auth",
Expand All @@ -38,26 +46,27 @@
"test:containers": "tests/test.sh",
"test": "tests/test.sh"
},
"dependencies": {
"@auth/core": "workspace:*"
},
"devDependencies": {
"@next-auth/adapter-test": "workspace:*",
"@next-auth/tsconfig": "workspace:*",
"jest": "^27.4.3",
"mssql": "^7.2.1",
"mysql": "^2.18.1",
"next-auth": "workspace:*",
"pg": "^8.7.3",
"sqlite3": "^5.0.8",
"typeorm": "0.3.7",
"typeorm": "0.3.15",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locked in on 0.3.15 as something is likely broken in 0.3.16

I think typeorm/typeorm#10041 would solve the issue.

"typeorm-naming-strategies": "^4.1.0",
"typescript": "^4.7.4"
},
"peerDependencies": {
"mssql": "^6.2.1 || 7",
"mysql": "^2.18.1",
"next-auth": "^4",
"pg": "^8.2.1",
"sqlite3": "^5.0.2",
"typeorm": "0.3.7"
"typeorm": "^0.3.7"
},
"peerDependenciesMeta": {
"mysql": {
Expand All @@ -76,4 +85,4 @@
"jest": {
"preset": "@next-auth/adapter-test/jest"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
* ## Installation
*
* ```bash npm2yarn2pnpm
* npm install next-auth @next-auth/typeorm-legacy-adapter typeorm
* npm install next-auth @auth/typeorm-adapter typeorm
* ```
*
* @module @next-auth/typeorm-legacy-adapter
* @module @auth/typeorm-adapter
*/
import type {
Adapter,
AdapterUser,
AdapterAccount,
AdapterSession,
} from "next-auth/adapters"
} from "@auth/core/adapters"
import { DataSourceOptions, DataSource, EntityManager } from "typeorm"
import * as defaultEntities from "./entities"
import { parseDataSourceConfig, updateConnectionEntities } from "./utils"
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function getManager(options: {
*
* ```javascript title="pages/api/auth/[...nextauth].js"
* import NextAuth from "next-auth"
* import { TypeORMLegacyAdapter } from "@next-auth/typeorm-legacy-adapter"
* import { TypeORMLegacyAdapter } from "@auth/typeorm-adapter"
*
*
* export default NextAuth({
Expand All @@ -93,7 +93,7 @@ export async function getManager(options: {
*
* 1. Create a file containing your modified entities:
*
* (The file below is based on the [default entities](https://github.com/nextauthjs/next-auth/blob/main/packages/adapter-typeorm-legacy/src/entities.ts))
* (The file below is based on the [default entities](https://github.com/nextauthjs/next-auth/blob/main/packages/adapter-typeorm/src/entities.ts))
*
* ```diff title="lib/entities.ts"
* import {
Expand Down Expand Up @@ -235,7 +235,7 @@ export async function getManager(options: {
*
* ```javascript title="pages/api/auth/[...nextauth].js"
* import NextAuth from "next-auth"
* import { TypeORMLegacyAdapter } from "@next-auth/typeorm-legacy-adapter"
* import { TypeORMLegacyAdapter } from "@auth/typeorm-adapter"
* import * as entities from "lib/entities"
*
* export default NextAuth({
Expand All @@ -260,7 +260,7 @@ export async function getManager(options: {
*
* ```javascript title="pages/api/auth/[...nextauth].js"
* import NextAuth from "next-auth"
* import { TypeORMLegacyAdapter } from "@next-auth/typeorm-legacy-adapter"
* import { TypeORMLegacyAdapter } from "@auth/typeorm-adapter"
* import { SnakeNamingStrategy } from 'typeorm-naming-strategies'
* import { ConnectionOptions } from "typeorm"
*
Expand Down Expand Up @@ -328,8 +328,10 @@ export function TypeORMLegacyAdapter(
},
async getUserByAccount(provider_providerAccountId) {
const m = await getManager(c)
// @ts-expect-error
const account = await m.findOne<AdapterAccount & { user: AdapterUser }>(
"AccountEntity",
// @ts-expect-error
{ where: provider_providerAccountId, relations: ["user"] }
)
if (!account) return null
Expand Down
27 changes: 27 additions & 0 deletions packages/adapter-typeorm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"extends": "@next-auth/tsconfig/tsconfig.base.json",
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"isolatedModules": true,
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"outDir": ".",
"rootDir": "src",
"skipDefaultLibCheck": true,
"strictNullChecks": true,
"stripInternal": true,
"declarationMap": true,
"declaration": true
},
"include": [
"src/**/*"
],
"exclude": [
"*.js",
"*.d.ts",
]
}
Loading
Loading