fix registrasi

deskripsi:
- fix registrasi dan middleware
This commit is contained in:
2025-02-05 17:48:45 +08:00
parent d7252b9fb3
commit 61f8e03c73
10 changed files with 199 additions and 173 deletions

View File

@@ -22,3 +22,5 @@
{"id":"c65237f0-e0cf-4961-9454-2405c4f4fe05","level":"info","message":"Success send message","status":"success","timestamp":"2025-02-05T06:41:30.785Z"} {"id":"c65237f0-e0cf-4961-9454-2405c4f4fe05","level":"info","message":"Success send message","status":"success","timestamp":"2025-02-05T06:41:30.785Z"}
{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at <anonymous> (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:53:59.012Z"} {"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at <anonymous> (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:53:59.012Z"}
{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T07:23:58.983Z"} {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T07:23:58.983Z"}
{"id":"64e3a991-7e44-407c-94b4-1693dc8a4417","level":"info","message":"Success send message","status":"success","timestamp":"2025-02-05T09:14:22.961Z"}
{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T09:43:37.753Z"}

View File

@@ -21,3 +21,4 @@
{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:148:1500)\n at handleRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:7367)\n at handleAndLogRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6687)\n at <anonymous> (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6394)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:35:53.417Z"} {"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:148:1500)\n at handleRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:7367)\n at handleAndLogRequestError (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6687)\n at <anonymous> (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/@prisma/client/runtime/binary.js:258:6394)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:35:53.417Z"}
{"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at <anonymous> (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:53:59.012Z"} {"clientVersion":"6.3.0","code":"UND_ERR_SOCKET","level":"error","message":"Error deleting OTP: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed","meta":{"modelName":"KodeOtp"},"name":"PrismaClientKnownRequestError","stack":"PrismaClientKnownRequestError: \nInvalid `prisma.kodeOtp.delete()` invocation:\n\n\nother side closed\n at new PrismaClientKnownRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:148:1505)\n at handleRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:7369)\n at handleAndLogRequestError (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6705)\n at <anonymous> (webpack-internal:///(ssr)/./node_modules/@prisma/client/runtime/binary.js:258:6418)\n at processTicksAndRejections (native:7:39)","timestamp":"2025-02-05T06:53:59.012Z"}
{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T07:23:58.983Z"} {"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T07:23:58.983Z"}
{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-05T09:43:37.753Z"}

View File

@@ -4,8 +4,16 @@ import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function POST(req: Request) { export async function POST(req: Request) {
if (req.method === "POST") { if (req.method !== "POST") {
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}
try {
const { data } = await req.json(); const { data } = await req.json();
console.log("data api register", data);
const cekUsername = await prisma.user.findUnique({ const cekUsername = await prisma.user.findUnique({
where: { where: {
@@ -13,12 +21,11 @@ export async function POST(req: Request) {
}, },
}); });
try {
if (cekUsername) if (cekUsername)
return NextResponse.json( return NextResponse.json({
{ success: false, message: "Username sudah digunakan" }, success: false,
{ status: 400 } message: "Username sudah digunakan",
); });
const createUser = await prisma.user.create({ const createUser = await prisma.user.create({
data: { data: {
@@ -28,6 +35,12 @@ export async function POST(req: Request) {
}, },
}); });
if (!createUser)
return NextResponse.json(
{ success: false, message: "Gagal Registrasi" },
{ status: 500 }
);
const token = await sessionCreate({ const token = await sessionCreate({
sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!, sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!,
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
@@ -35,24 +48,24 @@ export async function POST(req: Request) {
}); });
return NextResponse.json( return NextResponse.json(
{ success: true, message: "Berhasil Login", data: createUser }, {
{ status: 200 } success: true,
message: "Registrasi Berhasil, Anda Sedang Login",
// data: createUser,
},
{ status: 201 }
); );
} catch (error) { } catch (error) {
backendLogger.log("Error registrasi:", error); backendLogger.error("Error registrasi:", error);
return NextResponse.json( return NextResponse.json(
{ {
success: false, success: false,
message: "Server Error", message: "Maaf, Terjadi Keselahan",
reason: (error as Error).message, reason: (error as Error).message,
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}

View File

@@ -1,14 +1,21 @@
import { prisma } from "@/app/lib"; import { prisma } from "@/app/lib";
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp"; import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function POST(req: Request) { export async function POST(req: Request) {
if (req.method === "POST") { if (req.method !== "POST") {
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}
try {
const codeOtp = randomOTP(); const codeOtp = randomOTP();
const body = await req.json(); const body = await req.json();
const { nomor } = body; const { nomor } = body;
try {
const res = await fetch( const res = await fetch(
`https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya. `https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.
\n \n
@@ -51,8 +58,7 @@ export async function POST(req: Request) {
{ status: 200 } { status: 200 }
); );
} catch (error) { } catch (error) {
console.log(error); backendLogger.error(" Error Resend OTP", error);
return NextResponse.json( return NextResponse.json(
{ {
success: false, success: false,
@@ -60,10 +66,7 @@ export async function POST(req: Request) {
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}

View File

@@ -52,7 +52,7 @@ export async function POST(req: Request) {
return NextResponse.json( return NextResponse.json(
{ {
success: false, success: false,
message: "API Error or Server Error", message: "Maaf, Terjadi Keselahan",
reason: (error as Error).message, reason: (error as Error).message,
}, },
{ status: 500 } { status: 500 }

View File

@@ -3,7 +3,7 @@ import { NextResponse } from "next/server";
export async function GET(req: Request) { export async function GET(req: Request) {
const auth = req.headers.get("Authorization"); const auth = req.headers.get("Authorization");
const token = auth?.split(" ")[1]; const token = auth?.split(" ")[1];
console.log("TOKEN>", token);
if (!token) return NextResponse.json({ success: false }, { status: 401 }); if (!token) return NextResponse.json({ success: false }, { status: 401 });
return NextResponse.json({ success: true }); return NextResponse.json({ success: true });

View File

@@ -3,6 +3,7 @@ export {
apiGetCheckCodeOtp, apiGetCheckCodeOtp,
apiPostVerifikasiCodeOtp, apiPostVerifikasiCodeOtp,
apiDeleteAktivasiKodeOtpByNomor, apiDeleteAktivasiKodeOtpByNomor,
apiFetchRegister,
}; };
const apiFetchLogin = async ({ nomor }: { nomor: string }) => { const apiFetchLogin = async ({ nomor }: { nomor: string }) => {
@@ -43,7 +44,30 @@ const apiDeleteAktivasiKodeOtpByNomor = async ({ id }: { id: string }) => {
}, },
}); });
console.log("respone delete", await respone.json());
return await respone.json().catch(() => null); return await respone.json().catch(() => null);
}; };
const apiFetchRegister = async ({
nomor,
username,
}: {
nomor: string;
username: string;
}) => {
const data = {
username: username,
nomor: nomor,
};
const respone = await fetch("/api/auth/register", {
method: "POST",
body: JSON.stringify({ data }),
headers: {
"Content-Type": "application/json",
},
});
const result = await respone.json();
return result;
// return await respone.json().catch(() => null);
};

View File

@@ -14,8 +14,13 @@ import { useState } from "react";
import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id"; import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id";
import Register_SkeletonView from "./skeleton"; import Register_SkeletonView from "./skeleton";
import { clientLogger } from "@/util/clientLogger"; import { clientLogger } from "@/util/clientLogger";
import { apiGetCheckCodeOtp } from "../_lib/api_fetch_auth"; import {
apiDeleteAktivasiKodeOtpByNomor,
apiFetchRegister,
apiGetCheckCodeOtp,
} from "../_lib/api_fetch_auth";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global";
export default function Register() { export default function Register() {
const router = useRouter(); const router = useRouter();
@@ -48,52 +53,28 @@ export default function Register() {
} }
async function onRegistarsi() { async function onRegistarsi() {
const data = {
username: value,
nomor: nomor,
};
try { try {
setLoading(true); setLoading(true);
const res = await fetch("/api/auth/register", { const respone = await apiFetchRegister({ nomor: nomor, username: value });
method: "POST",
body: JSON.stringify({
data,
}),
headers: {
"Content-Type": "application/json",
},
});
const result = await res.json();
if (res.status === 200) {
ComponentGlobal_NotifikasiBerhasil(result.message);
localStorage.removeItem("hipmi_auth_code_id");
await auth_funDeleteAktivasiKodeOtpByNomor({
nomor: data.nomor,
});
if (respone.success) {
router.push("/waiting-room", { scroll: false }); router.push("/waiting-room", { scroll: false });
return; ComponentGlobal_NotifikasiBerhasil(respone.message);
}
if (res.status === 400) { try {
setLoading(false); const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({
ComponentGlobal_NotifikasiPeringatan(result.message); id: idCode,
return; });
}
if (res.status === 405) { if (responeDelete) {
setLoading(false); localStorage.removeItem("hipmi_auth_code_id");
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
} }
} catch (error) {
if (res.status === 500) { clientLogger.error("Error apiDeleteAktivasiKodeOtpByNomor:", error);
}
} else {
setLoading(false); setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message); ComponentGlobal_NotifikasiPeringatan(respone.message);
return;
} }
} catch (error) { } catch (error) {
setLoading(false); setLoading(false);
@@ -156,6 +137,7 @@ export default function Register() {
value.length < 5 || value.length < 5 ||
_.values(value).includes(" ") _.values(value).includes(" ")
} }
style={{ transition: "0.5s" }}
loading={loading ? true : false} loading={loading ? true : false}
loaderPosition="center" loaderPosition="center"
radius={"md"} radius={"md"}

View File

@@ -131,7 +131,6 @@ export default function Validasi() {
async function onBack() { async function onBack() {
try { try {
router.back(); router.back();
111;
const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({ const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({
id: idCode, id: idCode,
}); });
@@ -165,13 +164,12 @@ export default function Validasi() {
setTriggerOtp(true); setTriggerOtp(true);
setCounter(60); setCounter(60);
setLoadingResend(false); setLoadingResend(false);
// router.push("/validasi", { scroll: false });
} else { } else {
setLoadingResend(false); setLoadingResend(false);
ComponentGlobal_NotifikasiPeringatan(result.message); ComponentGlobal_NotifikasiPeringatan(result.message);
} }
} catch (error) { } catch (error) {
console.error(error); clientLogger.error(" Error onResend", error);
setLoadingResend(false); setLoadingResend(false);
ComponentGlobal_NotifikasiGagal("Terjadi Kesalahan"); ComponentGlobal_NotifikasiGagal("Terjadi Kesalahan");
} }
@@ -181,7 +179,6 @@ export default function Validasi() {
<> <>
<UIGlobal_LayoutDefault> <UIGlobal_LayoutDefault>
<Stack h={"100vh"}> <Stack h={"100vh"}>
{data && data.nomor !== "" ? (
<Box <Box
pt={"md"} pt={"md"}
px={"md"} px={"md"}
@@ -191,16 +188,17 @@ export default function Validasi() {
}} }}
> >
<ActionIcon variant="transparent" onClick={() => onBack()}> <ActionIcon variant="transparent" onClick={() => onBack()}>
{data && data.nomor !== "" ? (
<IconChevronLeft color="white" /> <IconChevronLeft color="white" />
</ActionIcon>
</Box>
) : ( ) : (
"" ""
)} )}
</ActionIcon>
</Box>
<Stack align="center" justify="center" h={"100vh"} spacing={50}> <Stack align="center" justify="center" h={"100vh"} spacing={50}>
<Title order={2} color={MainColor.yellow}> <Title order={2} color={MainColor.yellow}>
Verifikasi Kode OTP {data.code} Verifikasi Kode OTP
</Title> </Title>
<Stack spacing={"md"} align="center"> <Stack spacing={"md"} align="center">
@@ -232,18 +230,20 @@ export default function Validasi() {
</Center> </Center>
<Stack h={"5vh"} align="center" justify="center"> <Stack h={"5vh"} align="center" justify="center">
<Group position="center">
<Text fs="italic" c={MainColor.white}> <Text fs="italic" c={MainColor.white}>
Tidak menerima kode ?{" "} Tidak menerima kode ?{" "}
{counter > 0 ? ( </Text>
<Text fw={"bold"} inherit span> {data && data.nomor !== "" ? (
counter > 0 ? (
<Text fw={"bold"} c={MainColor.white}>
{counter + "s"} {counter + "s"}
</Text> </Text>
) : loadingResend ? ( ) : loadingResend ? (
<Loader ml={"sm"} size={"xs"} color="yellow" /> <Loader ml={"sm"} size={"xs"} color="yellow" />
) : ( ) : (
<Text <Text
inherit c={MainColor.white}
span
onClick={() => { onClick={() => {
onResendCode(); onResendCode();
}} }}
@@ -251,12 +251,19 @@ export default function Validasi() {
> >
Kirim ulang Kirim ulang
</Text> </Text>
)
) : (
<CustomSkeleton height={20} radius={"xl"} width={20} />
)} )}
</Text> </Group>
</Stack> </Stack>
</Stack> </Stack>
<Button <Button
w={300} w={300}
disabled={inputCode.length < 4 ? true : false}
style={{
transition: "all ease 0.3s",
}}
loading={loading ? true : false} loading={loading ? true : false}
loaderPosition="center" loaderPosition="center"
radius={"md"} radius={"md"}
@@ -265,9 +272,6 @@ export default function Validasi() {
c={"black"} c={"black"}
bg={MainColor.yellow} bg={MainColor.yellow}
color={"yellow"} color={"yellow"}
style={{
borderColor: AccentColor.yellow,
}}
onClick={() => { onClick={() => {
data.nomor == "" && data.code == "" data.nomor == "" && data.code == ""
? null ? null
@@ -277,8 +281,6 @@ export default function Validasi() {
<Text>VERIFIKASI</Text> <Text>VERIFIKASI</Text>
</Button> </Button>
</Stack> </Stack>
{/* {data.nomor == "" && data.code == "" ? <Validasi_SkeletonView /> : ""} */}
</Stack> </Stack>
</UIGlobal_LayoutDefault> </UIGlobal_LayoutDefault>
</> </>

View File

@@ -101,7 +101,6 @@ export const middleware = async (req: NextRequest) => {
// Verify token and get user data // Verify token and get user data
const user = await verifyToken({ token, encodedKey }); const user = await verifyToken({ token, encodedKey });
console.log("USER >>", user?.username);
// Handle login page access // Handle login page access
if (pathname === loginPath) { if (pathname === loginPath) {