Fix event & auth
Deskripsi: - Fix event kondisi user melewatkan event - Fix bug force-dynamic di beberapa api
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import { data } from "autoprefixer";
|
||||
import { NextResponse } from "next/server";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get("id");
|
||||
export async function GET(request: NextRequest) {
|
||||
const id = request.nextUrl.searchParams.get("id");
|
||||
// const { searchParams } = new URL(request.url);
|
||||
// const id = searchParams.get("id");
|
||||
|
||||
try {
|
||||
const data = await prisma.kodeOtp.findFirst({
|
||||
@@ -12,10 +14,10 @@ export async function GET(request: Request) {
|
||||
id: id as string,
|
||||
},
|
||||
});
|
||||
return new Response(JSON.stringify({ data }), { status: 200 });
|
||||
return NextResponse.json(data, { status: 200 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({ data: null }), { status: 404 });
|
||||
return NextResponse.json(null, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -18,14 +18,11 @@ export async function POST(req: Request) {
|
||||
|
||||
const sendWa = await res.json();
|
||||
if (sendWa.status !== "success")
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
message: "Nomor Whatsapp Tidak Aktif",
|
||||
}),
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Nomor Whatsapp Tidak Aktif" },
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
|
||||
const createOtpId = await prisma.kodeOtp.create({
|
||||
data: {
|
||||
nomor: nomor,
|
||||
@@ -34,32 +31,30 @@ export async function POST(req: Request) {
|
||||
});
|
||||
|
||||
if (!createOtpId)
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
message: "Gagal Membuat Kode OTP",
|
||||
}),
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Gagal Membuat Kode OTP" },
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Kode Verifikasi Dikirim",
|
||||
kodeId: createOtpId.id,
|
||||
}),
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
message: "Server Whatsapp Error !!",
|
||||
}),
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Server Whatsapp Error !! " },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
return NextResponse.json({ success: false });
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method Not Allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import { cookies } from "next/headers";
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get("id");
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
export const dynamic = "force-dynamic";
|
||||
export async function GET(request: NextRequest) {
|
||||
const id = request.nextUrl.searchParams.get("id");
|
||||
// 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 new Response(JSON.stringify({ success: true, message: "Logout Berhasil" }), {status: 200});
|
||||
}
|
||||
|
||||
// import { cookies } from "next/headers";
|
||||
// import { NextResponse } from "next/server";
|
||||
|
||||
// export async function GET() {
|
||||
// cookies().set({
|
||||
// name: "mySession",
|
||||
// value: "",
|
||||
// maxAge: 0,
|
||||
// });
|
||||
|
||||
// return NextResponse.json({ status: 200, message: "Logout" });
|
||||
// }
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Logout Berhasil" },
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { sessionCreate } from "@/app/auth/_lib/session_create";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
if (req.method === "POST") {
|
||||
@@ -12,11 +13,8 @@ export async function POST(req: Request) {
|
||||
});
|
||||
|
||||
if (cekUsername)
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
message: "Username sudah digunakan",
|
||||
}),
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Username sudah digunakan" },
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
@@ -43,28 +41,22 @@ export async function POST(req: Request) {
|
||||
});
|
||||
|
||||
if (!createUserSession)
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
message: "Gagal Membuat Session",
|
||||
}),
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Gagal Membuat Session" },
|
||||
{ status: 400 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
message: "Berhasil Login",
|
||||
}),
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Berhasil Login", data: createUser },
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
return new Response(
|
||||
JSON.stringify({ success: false, message: "Method Not Allowed" }),
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method Not Allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ export async function POST(req: Request) {
|
||||
|
||||
const sendWa = await res.json();
|
||||
if (sendWa.status !== "success")
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Nomor Whatsapp Tidak Aktif",
|
||||
}),
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
@@ -34,32 +34,36 @@ export async function POST(req: Request) {
|
||||
});
|
||||
|
||||
if (!createOtpId)
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Gagal Membuat Kode OTP",
|
||||
}),
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Kode Verifikasi Dikirim",
|
||||
kodeId: createOtpId.id,
|
||||
}),
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Server Whatsapp Error !!",
|
||||
}),
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
return NextResponse.json({ success: false });
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method Not Allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { sessionCreate } from "@/app/auth/_lib/session_create";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { ServerEnv } from "@/app/lib/server_env";
|
||||
import { sealData } from "iron-session";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { cookies } from "next/headers";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
@@ -23,10 +19,9 @@ export async function POST(req: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (dataUser === null)
|
||||
return new Response(
|
||||
JSON.stringify({ success: false, message: "Nomor Belum Terdaftar" }),
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Nomor Belum Terdaftar" },
|
||||
{ status: 404 }
|
||||
);
|
||||
|
||||
@@ -59,49 +54,27 @@ export async function POST(req: Request) {
|
||||
});
|
||||
|
||||
if (!createUserSession)
|
||||
return new Response(
|
||||
JSON.stringify({ success: false, message: "Gagal Membuat Session" }),
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Gagal Membuat Session" },
|
||||
{ status: 400 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
// if (data) {
|
||||
// const res = await sealData(
|
||||
// JSON.stringify({
|
||||
// id: data.id,
|
||||
// username: data.username,
|
||||
// }),
|
||||
// {
|
||||
// password: ServerEnv.value?.WIBU_PWD as string,
|
||||
// }
|
||||
// );
|
||||
|
||||
// cookies().set({
|
||||
// name: "mySession",
|
||||
// value: res,
|
||||
// maxAge: 60 * 60 * 24 * 7,
|
||||
// });
|
||||
|
||||
// revalidatePath("/dev/home");
|
||||
|
||||
// return NextResponse.json({ status: 200, data });
|
||||
// }
|
||||
|
||||
// return NextResponse.json({ success: true });
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Berhasil Login",
|
||||
roleId: dataUser.masterUserRoleId,
|
||||
active: dataUser.active,
|
||||
}),
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
return new Response(
|
||||
JSON.stringify({ success: false, message: "Method Not Allowed" }),
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method Not Allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function GET(req: Request) {
|
||||
|
||||
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) {
|
||||
return NextResponse.json({ success: false });
|
||||
// return new Response(JSON.stringify({ success: false }));
|
||||
|
||||
}
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { event_newGetListPesertaById } from "@/app_modules/event/fun";
|
||||
import { Event_getListPesertaById } from "@/app_modules/event/fun/get/get_list_peserta_by_id";
|
||||
import { toNumber } from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { headers } from "next/headers";
|
||||
import { NextResponse } from "next/server";
|
||||
export async function GET(req: Request) {
|
||||
const origin = new URL(req.url).origin;
|
||||
|
||||
return new Response(JSON.stringify({ success: true, origin }));
|
||||
return NextResponse.json({ success: true, origin });
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const page = new URL(req.url).searchParams.get("page");
|
||||
if (!page) return new Response("page require", { status: 400 });
|
||||
if (!page)
|
||||
return NextResponse.json({ message: "Page not found" }, { status: 400 });
|
||||
|
||||
const res = await prisma.projectCollaboration_Message.findMany({
|
||||
take: 5,
|
||||
skip: +page * 5 - 5,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const auth = req.headers.get("Authorization");
|
||||
const token = auth?.split(" ")[1];
|
||||
if (!token)
|
||||
return new Response(JSON.stringify({ success: false }), { status: 401 });
|
||||
return new Response(JSON.stringify({ success: true }));
|
||||
if (!token) return NextResponse.json({ success: false }, { status: 401 });
|
||||
return NextResponse.json({ success: true });
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { headers } from "next/headers";
|
||||
import { NextResponse } from "next/server";
|
||||
export async function GET(
|
||||
req: Request) {
|
||||
const origin = new URL(req.url).origin;
|
||||
|
||||
return new Response(JSON.stringify({ success: true, origin }));
|
||||
return NextResponse.json({ success: true, origin });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user