diff --git a/src/app/api/auth/check/route.ts b/src/app/api/auth/check/route.ts index d8176b13..b51a6f31 100644 --- a/src/app/api/auth/check/route.ts +++ b/src/app/api/auth/check/route.ts @@ -14,6 +14,7 @@ export async function GET(request: NextRequest) { id: id as string, }, }); + return NextResponse.json(data, { status: 200 }); } catch (error) { console.log(error); diff --git a/src/app/api/auth/logout/route.ts b/src/app/api/auth/logout/route.ts index 0f9be556..44a4a2ab 100644 --- a/src/app/api/auth/logout/route.ts +++ b/src/app/api/auth/logout/route.ts @@ -1,4 +1,3 @@ -import { prisma } from "@/app/lib"; import { cookies } from "next/headers"; import { NextRequest, NextResponse } from "next/server"; export const dynamic = "force-dynamic"; @@ -7,15 +6,15 @@ export async function GET(request: NextRequest) { // const { searchParams } = new URL(request.url); // const id = searchParams.get("id"); - const delToken = await prisma.userSession.delete({ - where: { - userId: id as string, - }, - }); + // const delToken = await prisma.userSession.delete({ + // where: { + // userId: id as string, + // }, + // }); const del = cookies().delete(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!); return NextResponse.json( { success: true, message: "Logout Berhasil" }, { status: 200 } ); - } +} diff --git a/src/app/api/auth/validasi/route.ts b/src/app/api/auth/validasi/route.ts index 2f432b70..05ee6b26 100644 --- a/src/app/api/auth/validasi/route.ts +++ b/src/app/api/auth/validasi/route.ts @@ -6,73 +6,76 @@ export async function POST(req: Request) { if (req.method === "POST") { const { nomor } = await req.json(); - const dataUser = await prisma.user.findUnique({ - where: { - nomor: nomor, - }, - select: { - id: true, - nomor: true, - username: true, - active: true, - masterUserRoleId: true, - }, - }); - - if (dataUser === null) - return NextResponse.json( - { success: false, message: "Nomor Belum Terdaftar" }, - { status: 404 } - ); - - const token = await sessionCreate({ - sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, - encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, - user: dataUser as any, - }); - - const cekSessionUser = await prisma.userSession.findFirst({ - where: { - userId: dataUser.id, - }, - }); - - if (cekSessionUser !== null) { - await prisma.userSession.delete({ - where: { - userId: dataUser.id, - }, - }); - } - try { - const createUserSession = await prisma.userSession.create({ - data: { - token: token as string, - userId: dataUser.id, + const dataUser = await prisma.user.findUnique({ + where: { + nomor: nomor, + }, + select: { + id: true, + nomor: true, + username: true, + active: true, + masterUserRoleId: true, }, }); - if (!createUserSession) + if (dataUser === null) return NextResponse.json( - { success: false, message: "Gagal Membuat Session" }, - { status: 400 } + { success: false, message: "Nomor Belum Terdaftar" }, + { status: 404 } ); + + const token = await sessionCreate({ + sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, + encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, + user: dataUser as any, + }); + + // const cekSessionUser = await prisma.userSession.findFirst({ + // where: { + // userId: dataUser.id, + // }, + // }); + + // if (cekSessionUser !== null) { + // await prisma.userSession.delete({ + // where: { + // userId: dataUser.id, + // }, + // }); + // } + + // try { + // const createUserSession = await prisma.userSession.create({ + // data: { + // token: token as string, + // userId: dataUser.id, + // }, + // }); + + // if (!createUserSession) + // return NextResponse.json( + // { success: false, message: "Gagal Membuat Session" }, + // { status: 400 } + // ); + // } catch (error) { + // console.log(error); + // } + + return NextResponse.json( + { + success: true, + message: "Berhasil Login", + roleId: dataUser.masterUserRoleId, + active: dataUser.active, + }, + { status: 200 } + ); } catch (error) { console.log(error); } - - return NextResponse.json( - { - success: true, - message: "Berhasil Login", - roleId: dataUser.masterUserRoleId, - active: dataUser.active, - }, - { status: 200 } - ); } - return NextResponse.json( { success: false, message: "Method Not Allowed" }, { status: 405 } diff --git a/src/app_modules/auth/validasi/view.tsx b/src/app_modules/auth/validasi/view.tsx index d817b00e..2429b25a 100644 --- a/src/app_modules/auth/validasi/view.tsx +++ b/src/app_modules/auth/validasi/view.tsx @@ -70,8 +70,8 @@ export default function Validasi() { const result = await res.json(); onSetData({ - nomor: result.data.nomor, - code: result.data.otp, + nomor: result.nomor, + code: result.otp, }); }