mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
added a api call /api/users
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"use server";
|
"use server";
|
||||||
import { eq, not , asc} from "drizzle-orm";
|
import { eq, not , asc} from "drizzle-orm";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { db } from "../db";
|
import { db } from "@db/index";
|
||||||
import { accounts } from "@schemas/schema";
|
import { accounts } from "@schemas/schema";
|
||||||
|
|
||||||
export const getData = async () => {
|
export const getData = async () => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use server";
|
"use server";
|
||||||
import { eq, not , asc} from "drizzle-orm";
|
import { eq, not , asc} from "drizzle-orm";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { db } from "../db";
|
import { db } from "@db/index";
|
||||||
import { brands } from "@schemas/schema";
|
import { brands } from "@schemas/schema";
|
||||||
export const getData = async () => {
|
export const getData = async () => {
|
||||||
const data = await db.select().from(brands).orderBy(asc(brands.name));
|
const data = await db.select().from(brands).orderBy(asc(brands.name));
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
"use server";
|
"use server";
|
||||||
import { eq, not , asc} from "drizzle-orm";
|
import { eq, not , asc} from "drizzle-orm";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { db } from "../db";
|
import { db } from "@db/index";
|
||||||
import { manufacturer } from "@schemas/schema";
|
import { manufacturer } from "@schemas/schema";
|
||||||
|
|
||||||
|
|
||||||
export const getData = async () => {
|
export const getData = async () => {
|
||||||
const data = await db.select().from(manufacturer).orderBy(asc(manufacturer.name));
|
const data = await db.select().from(manufacturer).orderBy(asc(manufacturer.name));
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compare the provided password with the stored hashed password
|
// 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) {
|
if (!isPasswordValid) {
|
||||||
return NextResponse.json({ error: 'Invalid email or password' }, { status: 401 });
|
return NextResponse.json({ error: 'Invalid email or password' }, { status: 401 });
|
||||||
|
|||||||
23
src/app/api/users/route.ts
Normal file
23
src/app/api/users/route.ts
Normal 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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user