diff --git a/bun.lockb b/bun.lockb index 7a00bb7..700c565 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 41e3790..727d430 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "node": ">=20.0.0" }, "dependencies": { - "@auth/mongodb-adapter": "^3.2.0", + "@auth/mongodb-adapter": "^3.4.2", "@auth/prisma-adapter": "^2.4.1", "@edgestore/react": "^0.1.7", "@edgestore/server": "^0.1.7", @@ -38,7 +38,7 @@ "@radix-ui/react-tooltip": "^1.0.7", "@react-email/components": "0.0.22", "@tailwindcss/typography": "^0.5.12", - "bcrypt": "^5.1.1", + "bcryptjs": "^2.4.3", "chart.js": "^4.4.3", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", @@ -48,11 +48,11 @@ "jose": "^5.6.2", "lint-staged": "^15.2.5", "lucide-react": "^0.396.0", - "mongodb": "^6.7.0", + "mongodb": "^6.8.0", "mongoose": "^8.5.3", "negotiator": "^0.6.3", "next": "14.1.4", - "next-auth": "^5.0.0-beta.19", + "next-auth": "^5.0.0-beta.20", "next-connect": "^1.0.0", "next-videos": "^1.4.1", "nextjs-toploader": "^1.6.12", @@ -72,6 +72,7 @@ "sweetalert2": "^11.12.0", "swiper": "^11.1.0", "tailwind-merge": "^2.2.2", + "tailwindcss-animate": "^1.0.7", "zod": "^3.23.8" }, "devDependencies": { @@ -80,6 +81,7 @@ "@biomejs/biome": "1.8.3", "@hookform/devtools": "^4.3.1", "@types/bcrypt": "^5.0.2", + "@types/bcryptjs": "^2.4.6", "@types/globalthis": "^1.0.4", "@types/negotiator": "^0.6.3", "@types/node": "^22.3.0", diff --git a/src/Internationalization/languages/bn.json b/src/Internationalization/languages/bn.json index df3f09f..1bcf3d8 100644 --- a/src/Internationalization/languages/bn.json +++ b/src/Internationalization/languages/bn.json @@ -62,11 +62,7 @@ "footerInfo": { "contact": { "title": "যোগাযোগ", - "value": [ - "০১৭৩১-৫১৯০২৫", - "০১৫৩৩-৮৮১১০২", - "০১৬৭৯-১১২৭২৫" - ] + "value": ["০১৭৩১-৫১৯০২৫", "০১৫৩৩-৮৮১১০২", "০১৬৭৯-১১২৭২৫"] }, "address": { "title": "ঠিকানা", @@ -140,4 +136,4 @@ "bookAppointment3": "ডাক্তারদের সাথে চিকিৎসা নিতে " } } -} \ No newline at end of file +} diff --git a/src/Internationalization/languages/en.json b/src/Internationalization/languages/en.json index 3927b6d..3d43fd4 100644 --- a/src/Internationalization/languages/en.json +++ b/src/Internationalization/languages/en.json @@ -62,11 +62,7 @@ "footerInfo": { "contact": { "title": "Contact", - "value": [ - "01731-519025", - "01533-881102", - "01679-112725" - ] + "value": ["01731-519025", "01533-881102", "01679-112725"] }, "address": { "title": "Address", @@ -139,4 +135,4 @@ "bookAppointment3": "with doctor and get treatment." } } -} \ No newline at end of file +} diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 0000000..7c62e2d --- /dev/null +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -0,0 +1,2 @@ +import { handlers } from "@/auth"; +export const { GET, POST } = handlers; diff --git a/src/auth.md b/src/auth.ts similarity index 67% rename from src/auth.md rename to src/auth.ts index 68b02df..4ca7743 100644 --- a/src/auth.md +++ b/src/auth.ts @@ -1,26 +1,16 @@ -import NextAuth from "next-auth" -import { MongoDBAdapter } from "@auth/mongodb-adapter" -import client from "./lib/mongoDBClientPromise" - +import mongoose from "mongoose"; +import { MongoDBAdapter } from "@auth/mongodb-adapter"; +import bcrypt from "bcryptjs"; -import bcrypt from "bcrypt"; +import NextAuth from "next-auth"; import Credentials from "next-auth/providers/credentials"; - import { signInSchema } from "@/schema"; -import mongoose from "mongoose"; +import connectDB from "./lib/connectDB"; +import client from "@/lib/MongoDBClient"; -export const { - handlers: { GET, POST }, - signIn, - signOut, - auth, -} = NextAuth({ +export const { handlers, signIn, signOut, auth } = NextAuth({ adapter: MongoDBAdapter(client), - - session: { - strategy: "jwt", - }, providers: [ Credentials({ credentials: { @@ -31,10 +21,8 @@ export const { if (credentials === null) return null; const { email, password } = await signInSchema.parseAsync(credentials); - await prisma.$connect(); - const user = await prisma.doctors.findFirst({ - where: { email: email }, - }); + await connectDB(); + const user = await mongoose.models.Doctor.findOne({ email: email }); if (!user) throw new Error("User not found"); diff --git a/src/lib/MongoDBClient.tsx b/src/lib/MongoDBClient.tsx new file mode 100644 index 0000000..fdebd7d --- /dev/null +++ b/src/lib/MongoDBClient.tsx @@ -0,0 +1,37 @@ +// This approach is taken from https://github.com/vercel/next.js/tree/canary/examples/with-mongodb +import { MongoClient, ServerApiVersion } from "mongodb"; + +if (!process.env.MONGODB_URI) { + throw new Error('Invalid/Missing environment variable: "MONGODB_URI"'); +} + +const uri = process.env.MONGODB_URI; +const options = { + serverApi: { + version: ServerApiVersion.v1, + strict: true, + deprecationErrors: true, + }, +}; + +let client: MongoClient; + +if (process.env.NODE_ENV === "development") { + // In development mode, use a global variable so that the value + // is preserved across module reloads caused by HMR (Hot Module Replacement). + const globalWithMongo = global as typeof globalThis & { + _mongoClient?: MongoClient; + }; + + if (!globalWithMongo._mongoClient) { + globalWithMongo._mongoClient = new MongoClient(uri, options); + } + client = globalWithMongo._mongoClient; +} else { + // In production mode, it's best to not use a global variable. + client = new MongoClient(uri, options); +} + +// Export a module-scoped MongoClient. By doing this in a +// separate module, the client can be shared across functions. +export default client; diff --git a/src/lib/dbClientPromise.ts b/src/lib/dbClientPromise.ts deleted file mode 100644 index 59f319d..0000000 --- a/src/lib/dbClientPromise.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { MongoClient, ServerApiVersion } from "mongodb"; - -(() => { - if (typeof global !== "undefined") { - (global as any).globalThis = global; - } else if (typeof self !== "undefined") { - (self as any).globalThis = self; - } else if (typeof window !== "undefined") { - (window as any).globalThis = window; - } else { - throw new Error("Unable to locate global object."); - } -})(); - -if (!process.env.DATABASE_URL) { - throw new Error('Invalid/Missing environment variable: "MONGODB_URI"'); -} - -const uri = process.env.DATABASE_URL; -const options = { - serverApi: { - version: ServerApiVersion.v1, - strict: true, - deprecationErrors: true, - }, -}; - -let client: any; -let mongoClientPromise: Promise; -type globalThis = any; - -if (process.env.NODE_ENV === "development") { - // In development mode, use a global variable so that the value - // is preserved across module reloads caused by HMR (Hot Module Replacement). - const globalWithMongo = global as globalThis & { - _mongoClientPromise?: Promise; - }; - - if (!globalWithMongo._mongoClientPromise) { - client = new MongoClient(uri, options); - globalWithMongo._mongoClientPromise = client.connect(); - } - if (globalWithMongo._mongoClientPromise) { - mongoClientPromise = globalWithMongo._mongoClientPromise; - } else { - client = new MongoClient(uri, options); - mongoClientPromise = client.connect(); - } -} else { - // In production mode, it's best to not use a global variable. - client = new MongoClient(uri, options); - mongoClientPromise = client.connect(); -} - -export { mongoClientPromise as dbClientPromise }; diff --git a/src/lib/index.ts b/src/lib/index.ts index 190128e..ceed685 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,2 +1,3 @@ -export * from "./dbClientPromise"; -// export * from "./prisma"; +export * from "./MongoDBClient"; +export * from "./connectDB"; +export * from "./edgestore"; diff --git a/src/middleware.ts b/src/middleware.ts index 3466395..0e6a0d9 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1,4 +1,5 @@ import { internationalization, sessionUpdate } from "@/middlewares"; +import { auth as authSession } from "@/auth"; import { createEdgeRouter } from "next-connect"; import type { NextFetchEvent, NextRequest } from "next/server"; @@ -6,10 +7,10 @@ import { NextResponse } from "next/server"; const router = createEdgeRouter(); router.use(internationalization); +// router.use(authSession); // router.use(sessionUpdate); -router.all(() => { - return NextResponse.next(); -}); + +router.all(() => NextResponse.next()); export function middleware(request: NextRequest, event: NextFetchEvent) { return router.run(request, event); diff --git a/tailwind.config.ts b/tailwind.config.ts index 4cbe191..91c5b1a 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -1,4 +1,5 @@ import type { Config } from "tailwindcss"; +import tailwindcssAnimate from "tailwindcss-animate"; const config = { darkMode: ["class"], @@ -110,7 +111,7 @@ const config = { }, }, }, - plugins: [], + plugins: [tailwindcssAnimate], } satisfies Config; export default config;