diff --git a/src/actions/accountActions.ts b/src/actions/accountActions.ts index f3eaf31..6d2cd5c 100644 --- a/src/actions/accountActions.ts +++ b/src/actions/accountActions.ts @@ -1,7 +1,7 @@ "use server"; import { eq, not , asc} from "drizzle-orm"; import { revalidatePath } from "next/cache"; -import { db } from "../db"; +import { db } from "@db/index"; import { accounts } from "@schemas/schema"; export const getData = async () => { diff --git a/src/actions/brandActions.ts b/src/actions/brandActions.ts index d8c4991..2668d65 100644 --- a/src/actions/brandActions.ts +++ b/src/actions/brandActions.ts @@ -1,7 +1,7 @@ "use server"; import { eq, not , asc} from "drizzle-orm"; import { revalidatePath } from "next/cache"; -import { db } from "../db"; +import { db } from "@db/index"; import { brands } from "@schemas/schema"; export const getData = async () => { const data = await db.select().from(brands).orderBy(asc(brands.name)); diff --git a/src/actions/manufacturerActions.ts b/src/actions/manufacturerActions.ts index 15b9fc0..0613264 100644 --- a/src/actions/manufacturerActions.ts +++ b/src/actions/manufacturerActions.ts @@ -1,8 +1,10 @@ "use server"; import { eq, not , asc} from "drizzle-orm"; import { revalidatePath } from "next/cache"; -import { db } from "../db"; +import { db } from "@db/index"; import { manufacturer } from "@schemas/schema"; + + export const getData = async () => { const data = await db.select().from(manufacturer).orderBy(asc(manufacturer.name)); return data; diff --git a/src/app/api/auth/signin/route.tsx b/src/app/api/auth/signin/route.tsx index 5977bd8..709d74a 100644 --- a/src/app/api/auth/signin/route.tsx +++ b/src/app/api/auth/signin/route.tsx @@ -20,7 +20,7 @@ export async function POST(request: Request) { } // Compare the provided password with the stored hashed password - const isPasswordValid = await bcrypt.compare(password, user.passwordHash); + const isPasswordValid = await bcrypt.compare(password, user.password_hash); if (!isPasswordValid) { return NextResponse.json({ error: 'Invalid email or password' }, { status: 401 }); diff --git a/src/app/api/users/route.ts b/src/app/api/users/route.ts new file mode 100644 index 0000000..ca473a6 --- /dev/null +++ b/src/app/api/users/route.ts @@ -0,0 +1,23 @@ + +import { eq, not, asc } from "drizzle-orm"; +import { revalidatePath } from "next/cache"; +import { db } from "@db/index"; +import { users } from "@schemas/schema"; +import { NextResponse } from "next/server"; + +export async function GET(request: Request) { + try { + // const { email, password } = await request.json(); + + // Fetch the user from the database + const data = await db.select().from(users) + + if (!data) { + return NextResponse.json({ error: 'Database connection Error', count: 0 }, { status: 401 }); + } + return NextResponse.json({ data, count: data.length }, { status: 200 }); + } catch (error) { + console.error('Sign in error:', error); + return NextResponse.json({ error: 'Database connection Error', count: 0 }, { status: 500 }); + } +} \ No newline at end of file