This commit is contained in:
2024-12-09 09:10:16 +08:00
parent 758626f2b0
commit 1dfaa4bb74
4 changed files with 69 additions and 66 deletions

View File

@@ -14,6 +14,7 @@ export async function GET(request: NextRequest) {
id: id as string, id: id as string,
}, },
}); });
return NextResponse.json(data, { status: 200 }); return NextResponse.json(data, { status: 200 });
} catch (error) { } catch (error) {
console.log(error); console.log(error);

View File

@@ -1,4 +1,3 @@
import { prisma } from "@/app/lib";
import { cookies } from "next/headers"; import { cookies } from "next/headers";
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -7,11 +6,11 @@ export async function GET(request: NextRequest) {
// const { searchParams } = new URL(request.url); // const { searchParams } = new URL(request.url);
// const id = searchParams.get("id"); // const id = searchParams.get("id");
const delToken = await prisma.userSession.delete({ // const delToken = await prisma.userSession.delete({
where: { // where: {
userId: id as string, // userId: id as string,
}, // },
}); // });
const del = cookies().delete(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!); const del = cookies().delete(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!);
return NextResponse.json( return NextResponse.json(

View File

@@ -6,6 +6,7 @@ export async function POST(req: Request) {
if (req.method === "POST") { if (req.method === "POST") {
const { nomor } = await req.json(); const { nomor } = await req.json();
try {
const dataUser = await prisma.user.findUnique({ const dataUser = await prisma.user.findUnique({
where: { where: {
nomor: nomor, nomor: nomor,
@@ -31,36 +32,36 @@ export async function POST(req: Request) {
user: dataUser as any, user: dataUser as any,
}); });
const cekSessionUser = await prisma.userSession.findFirst({ // const cekSessionUser = await prisma.userSession.findFirst({
where: { // where: {
userId: dataUser.id, // userId: dataUser.id,
}, // },
}); // });
if (cekSessionUser !== null) { // if (cekSessionUser !== null) {
await prisma.userSession.delete({ // await prisma.userSession.delete({
where: { // where: {
userId: dataUser.id, // userId: dataUser.id,
}, // },
}); // });
} // }
try { // try {
const createUserSession = await prisma.userSession.create({ // const createUserSession = await prisma.userSession.create({
data: { // data: {
token: token as string, // token: token as string,
userId: dataUser.id, // userId: dataUser.id,
}, // },
}); // });
if (!createUserSession) // if (!createUserSession)
return NextResponse.json( // return NextResponse.json(
{ success: false, message: "Gagal Membuat Session" }, // { success: false, message: "Gagal Membuat Session" },
{ status: 400 } // { status: 400 }
); // );
} catch (error) { // } catch (error) {
console.log(error); // console.log(error);
} // }
return NextResponse.json( return NextResponse.json(
{ {
@@ -71,8 +72,10 @@ export async function POST(req: Request) {
}, },
{ status: 200 } { status: 200 }
); );
} catch (error) {
console.log(error);
}
} }
return NextResponse.json( return NextResponse.json(
{ success: false, message: "Method Not Allowed" }, { success: false, message: "Method Not Allowed" },
{ status: 405 } { status: 405 }

View File

@@ -70,8 +70,8 @@ export default function Validasi() {
const result = await res.json(); const result = await res.json();
onSetData({ onSetData({
nomor: result.data.nomor, nomor: result.nomor,
code: result.data.otp, code: result.otp,
}); });
} }