diff --git a/app/(Customer)/About/page.tsx b/app/(Customer)/About/page.tsx index 3ff908af..abae1c23 100644 --- a/app/(Customer)/About/page.tsx +++ b/app/(Customer)/About/page.tsx @@ -11,17 +11,20 @@ export const metadata: Metadata = { const About = () => { return (
-
-
-
About us
-
-
- - +
+

About Us

+
+ +
+ + +
-
- +
+
+ +
); }; diff --git a/lib/auth.ts b/lib/auth.ts index 6bdb4f81..372f2a5a 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -1,11 +1,8 @@ - import CredentialsProvider from "next-auth/providers/credentials"; import { NextAuthOptions } from "next-auth"; -import sendEmail from "@/lib/sendEmail"; // Ensure this points to your sendEmail function +import sendEmail from "@/lib/sendEmail"; import prismadb from "./prismadb"; -// const prisma = new PrismaClient(); - export const NEXT_AUTH_CONFIG: NextAuthOptions = { providers: [ CredentialsProvider({ @@ -16,67 +13,29 @@ export const NEXT_AUTH_CONFIG: NextAuthOptions = { role: { label: "Role", type: "text" }, }, async authorize(credentials) { - if (!credentials?.email || !credentials?.otp || !credentials?.role) { - throw new Error("Invalid credentials"); - } + if (!credentials?.email || !credentials?.otp || !credentials?.role) throw new Error("Invalid credentials"); let account; - if (credentials.role === "user") { - account = await prismadb.user.findUnique({ - where: { email: credentials.email }, - }); - } else if (credentials.role === "seller"){ - account = await prismadb.seller.findUnique({ - where: { email: credentials.email }, - }); - }else if (credentials.role === "admin"){ - account = await prismadb.admin.findUnique({ - where: { email: credentials.email }, - }); - } - else{ - return null - } + if (credentials.role === "user") account = await prismadb.user.findUnique({ where: { email: credentials.email } }); + else if (credentials.role === "seller") account = await prismadb.seller.findUnique({ where: { email: credentials.email } }); + else if (credentials.role === "admin") account = await prismadb.admin.findUnique({ where: { email: credentials.email } }); + else return null; - if (!account) { - return null; - } - - // Verify OTP - if (credentials.otp !== account.otp) { - // Assuming 'otp' field exists in your User/Seller model - return null; - } + if (!account || credentials.otp !== account.otp) return null; const updateData = { otp: null }; - // Clear OTP after successful login - if (credentials.role === "user") { - await prismadb.user.update({ - where: { email: credentials.email }, - data: updateData, // Reset OTP or delete it after use - }); - } else if(credentials.role === "seller"){ - await prismadb.seller.update({ - where: { email: credentials.email }, - data: updateData, // Reset OTP or delete it after use - }); - }else if (credentials.role === "admin"){ - await prismadb.admin.update({ - where: { email: credentials.email }, - data: updateData, // Reset OTP or delete it after use - }); - } - else{ - return null - } + if (credentials.role === "user") await prismadb.user.update({ where: { email: credentials.email }, data: updateData }); + else if (credentials.role === "seller") await prismadb.seller.update({ where: { email: credentials.email }, data: updateData }); + else if (credentials.role === "admin") await prismadb.admin.update({ where: { email: credentials.email }, data: updateData }); + else return null; - const role = account.role == "user" ? "user" : account.role == "seller"? "seller" : "admin" + const role = account.role === "user" ? "user" : account.role === "seller" ? "seller" : "admin"; return { id: account.id, name: account.name, email: account.email, - role: role + role: role, }; }, }), @@ -86,68 +45,42 @@ export const NEXT_AUTH_CONFIG: NextAuthOptions = { jwt: async ({ token, user }) => { if (user) { token.uid = user.id; - token.role = user.role; // Store role in JWT token + token.role = user.role; } return token; }, session: async ({ session, token }) => { if (session.user) { session.user.id = token.uid; - session.user.role = token.role; // Pass role to session + session.user.role = token.role; } return session; }, }, }; -// Function to generate and send OTP -export const generateAndSendOTP = async ( - email: string, - role: string -) => { - const otp = Math.floor(100000 + Math.random() * 900000).toString(); // Generate 6-digit OTP - - // Store OTP in the user or seller record +export const generateAndSendOTP = async (email: string, role: string) => { + const otp = Math.floor(100000 + Math.random() * 900000).toString(); if (role === "user") { try { - await prismadb.user.update({ - where: { email }, - data: { otp }, // Ensure 'otp' field exists in your User model - }); + await prismadb.user.update({ where: { email }, data: { otp } }); } catch (err) { - console.error( - "DB Error sending OTP for user:", - err instanceof Error ? err.message : err - ); + console.error("DB Error sending OTP for user:", err instanceof Error ? err.message : err); return false; } } else if (role === "seller") { try { - await prismadb.seller.update({ - where: { email }, - data: { otp }, // Ensure 'otp' field exists in your User model - }); + await prismadb.seller.update({ where: { email }, data: { otp } }); } catch (err) { - console.error( - "DB Error sending OTP for seller:", - err instanceof Error ? err.message : err - ); + console.error("DB Error sending OTP for seller:", err instanceof Error ? err.message : err); return false; } - } - - else if (role === "admin") { + } else if (role === "admin") { try { - await prismadb.admin.update({ - where: { email }, - data: { otp }, // Ensure 'otp' field exists in your User model - }); + await prismadb.admin.update({ where: { email }, data: { otp } }); } catch (err) { - console.error( - "DB Error sending OTP for admin:", - err instanceof Error ? err.message : err - ); + console.error("DB Error sending OTP for admin:", err instanceof Error ? err.message : err); return false; } } @@ -162,14 +95,8 @@ export const generateAndSendOTP = async ( console.log("OTP email sent successfully:", response); return true; - // Handle success response if needed (e.g., logging messageId) } catch (err) { - console.error( - "Error sending OTP:", - err instanceof Error ? err.message : err - ); + console.error("Error sending OTP:", err instanceof Error ? err.message : err); return false; } }; - -// Call generateAndSendOTP(email) before redirecting to the login page to send OTP to the user