added a api call /api/users

This commit is contained in:
2025-01-16 21:26:30 -05:00
parent 9580f78ef5
commit fcaf392e83
5 changed files with 29 additions and 4 deletions

View File

@@ -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 () => {

View File

@@ -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));

View File

@@ -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;

View File

@@ -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 });

View File

@@ -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 });
}
}