From 9efc83193cad6701c290fe3008fbb80673a2fca2 Mon Sep 17 00:00:00 2001 From: spike014 Date: Tue, 30 Sep 2025 21:10:24 +0800 Subject: [PATCH] refactor: remove duplicate auth module and centralize authentication logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove duplicate src/lib/auth.ts file - Update middleware.ts to use @/modules/auth/utils/auth-utils - Maintain backward compatibility with aliasing - Reduce code duplication and improve project structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- middleware.ts | 2 +- src/lib/auth.ts | 40 ---------------------------------------- 2 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 src/lib/auth.ts diff --git a/middleware.ts b/middleware.ts index bf5a4b2..218385e 100644 --- a/middleware.ts +++ b/middleware.ts @@ -1,5 +1,5 @@ import { type NextRequest, NextResponse } from "next/server"; -import { getAuth } from "./src/lib/auth"; +import { getAuthInstance as getAuth } from "@/modules/auth/utils/auth-utils"; export async function middleware(request: NextRequest) { try { diff --git a/src/lib/auth.ts b/src/lib/auth.ts deleted file mode 100644 index c59ae87..0000000 --- a/src/lib/auth.ts +++ /dev/null @@ -1,40 +0,0 @@ -/** biome-ignore-all lint/style/noNonNullAssertion: */ -import { getCloudflareContext } from "@opennextjs/cloudflare"; -import { betterAuth } from "better-auth"; -import { drizzleAdapter } from "better-auth/adapters/drizzle"; -import { nextCookies } from "better-auth/next-js"; -import { getDb } from "@/db"; - -let authInstance: ReturnType | null = null; - -const createAuth = async () => { - if (authInstance) { - return authInstance; - } - - const { env } = await getCloudflareContext({ async: true }); - const db = await getDb(); - authInstance = betterAuth({ - secret: env.BETTER_AUTH_SECRET, - database: drizzleAdapter(db, { - provider: "sqlite", - }), - emailAndPassword: { - enabled: true, - }, - socialProviders: { - google: { - enabled: true, - clientId: env.GOOGLE_CLIENT_ID!, - clientSecret: env.GOOGLE_CLIENT_SECRET!, - }, - }, - plugins: [nextCookies()], - }); - - return authInstance; -}; - -export const getAuth = async () => { - return await createAuth(); -};