fix registrasi
deskripsi: - fix registrasi dan middleware
This commit is contained in:
@@ -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"}
|
||||||
|
|||||||
@@ -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"}
|
||||||
|
|||||||
@@ -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,46 +21,51 @@ export async function POST(req: Request) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
if (cekUsername)
|
||||||
if (cekUsername)
|
return NextResponse.json({
|
||||||
return NextResponse.json(
|
success: false,
|
||||||
{ success: false, message: "Username sudah digunakan" },
|
message: "Username sudah digunakan",
|
||||||
{ status: 400 }
|
|
||||||
);
|
|
||||||
|
|
||||||
const createUser = await prisma.user.create({
|
|
||||||
data: {
|
|
||||||
username: data.username,
|
|
||||||
nomor: data.nomor,
|
|
||||||
active: false,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const token = await sessionCreate({
|
const createUser = await prisma.user.create({
|
||||||
sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!,
|
data: {
|
||||||
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
|
username: data.username,
|
||||||
user: createUser as any,
|
nomor: data.nomor,
|
||||||
});
|
active: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!createUser)
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ success: true, message: "Berhasil Login", data: createUser },
|
{ success: false, message: "Gagal Registrasi" },
|
||||||
{ status: 200 }
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
backendLogger.log("Error registrasi:", error);
|
|
||||||
return NextResponse.json(
|
|
||||||
{
|
|
||||||
success: false,
|
|
||||||
message: "Server Error",
|
|
||||||
reason: (error as Error).message,
|
|
||||||
},
|
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NextResponse.json(
|
const token = await sessionCreate({
|
||||||
{ success: false, message: "Method Not Allowed" },
|
sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!,
|
||||||
{ status: 405 }
|
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
|
||||||
);
|
user: createUser as any,
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: true,
|
||||||
|
message: "Registrasi Berhasil, Anda Sedang Login",
|
||||||
|
// data: createUser,
|
||||||
|
},
|
||||||
|
{ status: 201 }
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
backendLogger.error("Error registrasi:", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Maaf, Terjadi Keselahan",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
await prisma.$disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,69 +1,72 @@
|
|||||||
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
|
||||||
>> Kode OTP anda: ${codeOtp}.
|
>> Kode OTP anda: ${codeOtp}.
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
const sendWa = await res.json();
|
|
||||||
if (sendWa.status !== "success")
|
|
||||||
return NextResponse.json(
|
|
||||||
{
|
|
||||||
success: false,
|
|
||||||
message: "Nomor Whatsapp Tidak Aktif",
|
|
||||||
},
|
|
||||||
{ status: 400 }
|
|
||||||
);
|
|
||||||
|
|
||||||
const createOtpId = await prisma.kodeOtp.create({
|
|
||||||
data: {
|
|
||||||
nomor: nomor,
|
|
||||||
otp: codeOtp,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!createOtpId)
|
|
||||||
return NextResponse.json(
|
|
||||||
{
|
|
||||||
success: false,
|
|
||||||
message: "Gagal Membuat Kode OTP",
|
|
||||||
},
|
|
||||||
{ status: 400 }
|
|
||||||
);
|
|
||||||
|
|
||||||
return NextResponse.json(
|
|
||||||
{
|
|
||||||
success: true,
|
|
||||||
message: "Kode Verifikasi Dikirim",
|
|
||||||
kodeId: createOtpId.id,
|
|
||||||
},
|
|
||||||
{ status: 200 }
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
|
|
||||||
|
const sendWa = await res.json();
|
||||||
|
if (sendWa.status !== "success")
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: "Server Whatsapp Error !!",
|
message: "Nomor Whatsapp Tidak Aktif",
|
||||||
},
|
},
|
||||||
{ status: 500 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
const createOtpId = await prisma.kodeOtp.create({
|
||||||
|
data: {
|
||||||
|
nomor: nomor,
|
||||||
|
otp: codeOtp,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!createOtpId)
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Gagal Membuat Kode OTP",
|
||||||
|
},
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: true,
|
||||||
|
message: "Kode Verifikasi Dikirim",
|
||||||
|
kodeId: createOtpId.id,
|
||||||
|
},
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
backendLogger.error(" Error Resend OTP", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Server Whatsapp Error !!",
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
await prisma.$disconnect();
|
||||||
}
|
}
|
||||||
return NextResponse.json(
|
|
||||||
{ success: false, message: "Method Not Allowed" },
|
|
||||||
{ status: 405 }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 }
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
|||||||
@@ -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);
|
||||||
|
};
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
localStorage.removeItem("hipmi_auth_code_id");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
clientLogger.error("Error apiDeleteAktivasiKodeOtpByNomor:", error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
ComponentGlobal_NotifikasiPeringatan(result.message);
|
ComponentGlobal_NotifikasiPeringatan(respone.message);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res.status === 500) {
|
|
||||||
setLoading(false);
|
|
||||||
ComponentGlobal_NotifikasiPeringatan(result.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"}
|
||||||
|
|||||||
@@ -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,26 +179,26 @@ 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"}
|
style={{
|
||||||
style={{
|
position: "sticky",
|
||||||
position: "sticky",
|
top: 0,
|
||||||
top: 0,
|
}}
|
||||||
}}
|
>
|
||||||
>
|
<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,31 +230,40 @@ export default function Validasi() {
|
|||||||
</Center>
|
</Center>
|
||||||
|
|
||||||
<Stack h={"5vh"} align="center" justify="center">
|
<Stack h={"5vh"} align="center" justify="center">
|
||||||
<Text fs="italic" c={MainColor.white}>
|
<Group position="center">
|
||||||
Tidak menerima kode ?{" "}
|
<Text fs="italic" c={MainColor.white}>
|
||||||
{counter > 0 ? (
|
Tidak menerima kode ?{" "}
|
||||||
<Text fw={"bold"} inherit span>
|
</Text>
|
||||||
{counter + "s"}
|
{data && data.nomor !== "" ? (
|
||||||
</Text>
|
counter > 0 ? (
|
||||||
) : loadingResend ? (
|
<Text fw={"bold"} c={MainColor.white}>
|
||||||
<Loader ml={"sm"} size={"xs"} color="yellow" />
|
{counter + "s"}
|
||||||
|
</Text>
|
||||||
|
) : loadingResend ? (
|
||||||
|
<Loader ml={"sm"} size={"xs"} color="yellow" />
|
||||||
|
) : (
|
||||||
|
<Text
|
||||||
|
c={MainColor.white}
|
||||||
|
onClick={() => {
|
||||||
|
onResendCode();
|
||||||
|
}}
|
||||||
|
fw={"bold"}
|
||||||
|
>
|
||||||
|
Kirim ulang
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
) : (
|
) : (
|
||||||
<Text
|
<CustomSkeleton height={20} radius={"xl"} width={20} />
|
||||||
inherit
|
|
||||||
span
|
|
||||||
onClick={() => {
|
|
||||||
onResendCode();
|
|
||||||
}}
|
|
||||||
fw={"bold"}
|
|
||||||
>
|
|
||||||
Kirim ulang
|
|
||||||
</Text>
|
|
||||||
)}
|
)}
|
||||||
</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>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user