diff --git a/.github/ISSUE_TEMPLATE/3_bug_adapter.yml b/.github/ISSUE_TEMPLATE/3_bug_adapter.yml index 3898e6a3..a504ccde 100644 --- a/.github/ISSUE_TEMPLATE/3_bug_adapter.yml +++ b/.github/ISSUE_TEMPLATE/3_bug_adapter.yml @@ -25,7 +25,7 @@ body: - "@auth/dynamodb-adapter" - "@next-auth/fauna-adapter" - "@next-auth/firebase-adapter" - - "@next-auth/mikro-orm-adapter" + - "@auth/mikro-orm-adapter" - "@auth/mongodb-adapter" - "@next-auth/neo4j-adapter" - "@next-auth/pouchdb-adapter" diff --git a/.github/issue-labeler.yml b/.github/issue-labeler.yml index d926e5b0..ae3c0cce 100644 --- a/.github/issue-labeler.yml +++ b/.github/issue-labeler.yml @@ -13,7 +13,7 @@ firebase: - "@next-auth/firebase-adapter" mikro-orm: - - "@next-auth/mikro-orm-adapter" + - "@auth/mikro-orm-adapter" mongodb: - "@auth/mongodb-adapter" diff --git a/packages/adapter-mikro-orm/README.md b/packages/adapter-mikro-orm/README.md index ffa08208..7d1ef427 100644 --- a/packages/adapter-mikro-orm/README.md +++ b/packages/adapter-mikro-orm/README.md @@ -8,14 +8,14 @@

MikroORM Adapter - NextAuth.js / Auth.js

- + TypeScript - - npm + + npm - - Downloads + + Downloads Github Stars diff --git a/packages/adapter-mikro-orm/package.json b/packages/adapter-mikro-orm/package.json index 242d5603..4f050301 100644 --- a/packages/adapter-mikro-orm/package.json +++ b/packages/adapter-mikro-orm/package.json @@ -1,7 +1,7 @@ { - "name": "@next-auth/mikro-orm-adapter", - "version": "3.0.1", - "description": "MikroORM adapter for next-auth.", + "name": "@auth/mikro-orm-adapter", + "version": "0.0.0", + "description": "MikroORM adapter for Auth.js", "homepage": "https://authjs.dev", "repository": "https://github.com/nextauthjs/next-auth", "bugs": { @@ -11,7 +11,20 @@ "contributors": [ "Balázs Orbán " ], - "main": "dist/index.js", + "type": "module", + "types": "./index.d.ts", + "files": [ + "*.js", + "*.d.ts*", + "lib", + "src" + ], + "exports": { + ".": { + "types": "./index.d.ts", + "import": "./index.js" + } + }, "license": "ISC", "keywords": [ "next-auth", @@ -27,25 +40,18 @@ "test": "jest --runInBand", "build": "tsc" }, - "files": [ - "README.md", - "dist" - ], "peerDependencies": { - "@mikro-orm/core": "^5", - "next-auth": "^4" + "@mikro-orm/core": "^5" }, "devDependencies": { "@mikro-orm/core": "^5", "@mikro-orm/sqlite": "^5", "@next-auth/adapter-test": "workspace:*", "@next-auth/tsconfig": "workspace:*", - "@types/uuid": ">=8", - "jest": "^29", - "next-auth": "workspace:*" + "jest": "^29" }, "dependencies": { - "uuid": "^9" + "@auth/core": "workspace:*" }, "jest": { "preset": "@next-auth/adapter-test/jest" diff --git a/packages/adapter-mikro-orm/src/index.ts b/packages/adapter-mikro-orm/src/index.ts index c3e5b543..6ee1357c 100644 --- a/packages/adapter-mikro-orm/src/index.ts +++ b/packages/adapter-mikro-orm/src/index.ts @@ -9,10 +9,10 @@ * ## Installation * * ```bash npm2yarn2pnpm - * npm install next-auth @next-auth/dynamodb-adapter @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb + * npm install @mikro-orm/core @auth/mikro-orm-adapter * ``` * - * @module @next-auth/dynamodb-adapter + * @module @auth/mikro-orm-adapter */ import type { Connection, @@ -20,11 +20,11 @@ import type { Options as ORMOptions, } from "@mikro-orm/core" -import type { Adapter } from "next-auth/adapters" +import type { Adapter } from "@auth/core/adapters" import { MikroORM, wrap } from "@mikro-orm/core" -import * as defaultEntities from "./entities" +import * as defaultEntities from "./lib/entities" export { defaultEntities } @@ -35,7 +35,7 @@ export { defaultEntities } * * ```typescript title="pages/api/auth/[...nextauth].ts" * import NextAuth from "next-auth" - * import { MikroOrmAdapter } from "@next-auth/mikro-orm-adapter" + * import { MikroOrmAdapter } from "@auth/mikro-orm-adapter" * * export default NextAuth({ * adapter: MikroOrmAdapter({ @@ -67,7 +67,7 @@ export { defaultEntities } * Property, * Unique, * } from "@mikro-orm/core" - * import { defaultEntities } from "@next-auth/mikro-orm-adapter" + * import { defaultEntities } from "@auth/mikro-orm-adapter" * * const { Account, Session } = defaultEntities * @@ -124,7 +124,7 @@ export { defaultEntities } * * ```typescript title="config/mikro-orm.ts" * import { Options } from "@mikro-orm/core"; - * import { defaultEntities } from "@next-auth/mikro-orm-adapter" + * import { defaultEntities } from "@auth/mikro-orm-adapter" * * const config: Options = { * ... @@ -186,7 +186,6 @@ export function MikroOrmAdapter< * Method used in testing. You won't need to call this in your app. * @internal */ - // @ts-expect-error async __disconnect() { const em = await getEM() await em.getConnection().close() @@ -240,6 +239,7 @@ export function MikroOrmAdapter< return wrap(user).toObject() }, + // @ts-expect-error async linkAccount(data) { const em = await getEM() const user = await em.findOne(UserModel, { id: data.userId }) @@ -251,6 +251,7 @@ export function MikroOrmAdapter< return wrap(account).toObject() }, + // @ts-expect-error async unlinkAccount(provider_providerAccountId) { const em = await getEM() const account = await em.findOne(AccountModel, { diff --git a/packages/adapter-mikro-orm/src/entities.ts b/packages/adapter-mikro-orm/src/lib/entities.ts similarity index 92% rename from packages/adapter-mikro-orm/src/entities.ts rename to packages/adapter-mikro-orm/src/lib/entities.ts index c5fcd4b1..8271fdf9 100644 --- a/packages/adapter-mikro-orm/src/entities.ts +++ b/packages/adapter-mikro-orm/src/lib/entities.ts @@ -1,5 +1,3 @@ -import { v4 as randomUUID } from "uuid" - import { Property, Unique, @@ -16,8 +14,7 @@ import type { AdapterAccount, AdapterSession, VerificationToken as AdapterVerificationToken, -} from "next-auth/adapters" -import type { ProviderType } from "next-auth/providers" +} from "@auth/core/adapters" type RemoveIndex = { // eslint-disable-next-line @typescript-eslint/ban-types @@ -27,7 +24,7 @@ type RemoveIndex = { @Entity() export class User implements RemoveIndex { @PrimaryKey() - id: string = randomUUID() + id: string = crypto.randomUUID() @Property({ type: types.string, nullable: true }) name?: string @@ -63,7 +60,7 @@ export class User implements RemoveIndex { export class Session implements AdapterSession { @PrimaryKey() @Property({ type: types.string }) - id: string = randomUUID() + id: string = crypto.randomUUID() @ManyToOne({ entity: "User", @@ -88,7 +85,7 @@ export class Session implements AdapterSession { export class Account implements RemoveIndex { @PrimaryKey() @Property({ type: types.string }) - id: string = randomUUID() + id: string = crypto.randomUUID() @ManyToOne({ entity: "User", @@ -101,7 +98,7 @@ export class Account implements RemoveIndex { userId!: string @Property({ type: types.string }) - type!: ProviderType + type!: AdapterAccount["type"] @Property({ type: types.string }) provider!: string diff --git a/packages/adapter-mikro-orm/tests/entities.test.ts b/packages/adapter-mikro-orm/tests/entities.test.ts index d28acfaa..6149b2c8 100644 --- a/packages/adapter-mikro-orm/tests/entities.test.ts +++ b/packages/adapter-mikro-orm/tests/entities.test.ts @@ -13,13 +13,15 @@ import { Options, types, } from "@mikro-orm/core" -import { randomUUID, runBasicTests } from "@next-auth/adapter-test" +import { runBasicTests } from "@next-auth/adapter-test" + +globalThis.crypto ??= require("node:crypto").webcrypto @Entity() export class User implements defaultEntities.User { @PrimaryKey() @Property({ type: types.string }) - id: string = randomUUID() + id: string = crypto.randomUUID() @Property({ type: types.string, nullable: true }) name?: string @@ -60,7 +62,7 @@ export class User implements defaultEntities.User { export class VeryImportantEntity { @PrimaryKey() @Property({ type: types.string }) - id: string = randomUUID() + id: string = crypto.randomUUID() @Property({ type: types.boolean }) important = true diff --git a/packages/adapter-mikro-orm/tsconfig.json b/packages/adapter-mikro-orm/tsconfig.json index c704f64c..08f89628 100644 --- a/packages/adapter-mikro-orm/tsconfig.json +++ b/packages/adapter-mikro-orm/tsconfig.json @@ -1,13 +1,27 @@ { - "extends": "@next-auth/tsconfig/tsconfig.adapters.json", + "extends": "@next-auth/tsconfig/tsconfig.base.json", "compilerOptions": { - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "esModuleInterop": true, + "allowJs": true, + "baseUrl": ".", + "isolatedModules": true, + "target": "ES2020", + "module": "ESNext", + "moduleResolution": "node", + "outDir": ".", "rootDir": "src", - "outDir": "dist", - "stripInternal": true + "skipDefaultLibCheck": true, + "strictNullChecks": true, + "stripInternal": true, + "declarationMap": true, + "declaration": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true }, - "include": ["src"], - "exclude": ["dist", "test", "node_modules"] -} + "include": [ + "src/**/*", + ], + "exclude": [ + "*.js", + "*.d.ts", + ] +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 049887c9..f8d023cc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -327,24 +327,20 @@ importers: packages/adapter-mikro-orm: specifiers: + '@auth/core': workspace:* '@mikro-orm/core': ^5 '@mikro-orm/sqlite': ^5 '@next-auth/adapter-test': workspace:* '@next-auth/tsconfig': workspace:* - '@types/uuid': '>=8' jest: ^29 - next-auth: workspace:* - uuid: ^9 dependencies: - uuid: 9.0.0 + '@auth/core': link:../core devDependencies: '@mikro-orm/core': 5.2.1_@mikro-orm+sqlite@5.2.1 '@mikro-orm/sqlite': 5.2.1_@mikro-orm+core@5.2.1 '@next-auth/adapter-test': link:../adapter-test '@next-auth/tsconfig': link:../tsconfig - '@types/uuid': 8.3.4 jest: 29.3.0 - next-auth: link:../next-auth packages/adapter-mongodb: specifiers: diff --git a/turbo.json b/turbo.json index 65c19671..6ff65dc3 100644 --- a/turbo.json +++ b/turbo.json @@ -59,7 +59,7 @@ "@auth/dynamodb-adapter#build", "@next-auth/fauna-adapter#build", "@next-auth/firebase-adapter#build", - "@next-auth/mikro-orm-adapter#build", + "@auth/mikro-orm-adapter#build", "@auth/mongodb-adapter#build", "@next-auth/neo4j-adapter#build", "@next-auth/pouchdb-adapter#build", @@ -82,7 +82,7 @@ "@auth/dynamodb-adapter#build", "@next-auth/fauna-adapter#build", "@next-auth/firebase-adapter#build", - "@next-auth/mikro-orm-adapter#build", + "@auth/mikro-orm-adapter#build", "@auth/mongodb-adapter#build", "@next-auth/neo4j-adapter#build", "@next-auth/pouchdb-adapter#build",