From 6b73899ecc19e7f7f8ece9a404d2a5662ce490de Mon Sep 17 00:00:00 2001 From: Catalin Pit <25515812+catalinpit@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:46:53 +0200 Subject: [PATCH] chore: re-arrange stuff --- packages/lib/next-auth/auth-options.ts | 13 +------------ packages/lib/next-auth/kysely-db/db.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 packages/lib/next-auth/kysely-db/db.ts diff --git a/packages/lib/next-auth/auth-options.ts b/packages/lib/next-auth/auth-options.ts index acf614051..f04de55f8 100644 --- a/packages/lib/next-auth/auth-options.ts +++ b/packages/lib/next-auth/auth-options.ts @@ -1,7 +1,6 @@ /// import { KyselyAdapter } from '@auth/kysely-adapter'; import { compare } from '@node-rs/bcrypt'; -import { Kysely, PostgresDialect } from 'kysely'; import { DateTime } from 'luxon'; import type { AuthOptions, Session, User } from 'next-auth'; import type { JWT } from 'next-auth/jwt'; @@ -9,11 +8,9 @@ import CredentialsProvider from 'next-auth/providers/credentials'; import type { GoogleProfile } from 'next-auth/providers/google'; import GoogleProvider from 'next-auth/providers/google'; import { env } from 'next-runtime-env'; -import { Pool } from 'pg'; import { prisma } from '@documenso/prisma'; import { IdentityProvider, UserSecurityAuditLogType } from '@documenso/prisma/client'; -import type { DB } from '@documenso/prisma/generated/types.js'; import { isTwoFactorAuthenticationEnabled } from '../server-only/2fa/is-2fa-availble'; import { validateTwoFactorAuthentication } from '../server-only/2fa/validate-2fa'; @@ -22,15 +19,7 @@ import { getUserByEmail } from '../server-only/user/get-user-by-email'; import { sendConfirmationToken } from '../server-only/user/send-confirmation-token'; import { extractNextAuthRequestMetadata } from '../universal/extract-request-metadata'; import { ErrorCode } from './error-codes'; - -// move this from here -const db = new Kysely({ - dialect: new PostgresDialect({ - pool: new Pool({ - connectionString: process.env.DATABASE_URL, - }), - }), -}); +import { db } from './kysely-db/db'; export const NEXT_AUTH_OPTIONS: AuthOptions = { //@ts-expect-error - https://github.com/nextauthjs/next-auth/issues/8660 diff --git a/packages/lib/next-auth/kysely-db/db.ts b/packages/lib/next-auth/kysely-db/db.ts new file mode 100644 index 000000000..6f6f78ef9 --- /dev/null +++ b/packages/lib/next-auth/kysely-db/db.ts @@ -0,0 +1,14 @@ +import { KyselyAuth } from '@auth/kysely-adapter'; +import type { Codegen } from '@auth/kysely-adapter'; +import { PostgresDialect } from 'kysely'; +import { Pool } from 'pg'; + +import type { DB } from '@documenso/prisma/generated/types'; + +export const db = new KyselyAuth({ + dialect: new PostgresDialect({ + pool: new Pool({ + connectionString: process.env.DATABASE_URL, + }), + }), +});