Merge branch 'main' into stg
This commit is contained in:
@@ -6,13 +6,6 @@ import { sendCodeOtp } from "../_lib/sendCodeOtp";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
if (req.method !== "POST") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method Not Allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const { nomor } = await req.json();
|
||||
|
||||
@@ -43,18 +36,26 @@ export async function POST(req: Request) {
|
||||
});
|
||||
|
||||
if (!waResponse.ok) {
|
||||
console.error(`⚠️ WA Service HTTP Error: ${waResponse.status} ${waResponse.statusText}. Continuing since OTP is logged.`);
|
||||
console.error(
|
||||
`⚠️ WA Service HTTP Error: ${waResponse.status} ${waResponse.statusText}. Continuing since OTP is logged.`
|
||||
);
|
||||
console.log(`💡 Use this OTP to login: ${codeOtp}`);
|
||||
} else {
|
||||
const sendWa = await waResponse.json();
|
||||
console.log("📱 WA Response:", sendWa);
|
||||
|
||||
if (sendWa.status !== "success") {
|
||||
console.error("⚠️ WA Service Logic Error:", sendWa);
|
||||
}
|
||||
}
|
||||
} catch (waError: unknown) {
|
||||
const errorMessage = waError instanceof Error ? waError.message : String(waError);
|
||||
console.error("⚠️ WA Connection Exception. Continuing since OTP is logged.", errorMessage);
|
||||
const errorMessage =
|
||||
waError instanceof Error ? waError.message : String(waError);
|
||||
|
||||
console.error(
|
||||
"⚠️ WA Connection Exception. Continuing since OTP is logged.",
|
||||
errorMessage
|
||||
);
|
||||
}
|
||||
|
||||
const createOtpId = await prisma.kodeOtp.create({
|
||||
@@ -62,12 +63,12 @@ export async function POST(req: Request) {
|
||||
});
|
||||
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.set('auth_flow', 'login', {
|
||||
cookieStore.set("auth_flow", "login", {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
sameSite: 'lax',
|
||||
maxAge: 60 * 5, // 5 menit
|
||||
path: '/'
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "lax",
|
||||
maxAge: 60 * 5,
|
||||
path: "/",
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
@@ -85,6 +86,7 @@ export async function POST(req: Request) {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("❌ Error Login:", error);
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Terjadi kesalahan saat login" },
|
||||
{ status: 500 }
|
||||
|
||||
@@ -29,16 +29,18 @@ process.on('unhandledRejection', async (error) => {
|
||||
});
|
||||
|
||||
// Handle graceful shutdown
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('Received SIGINT signal. Closing database connections...');
|
||||
await prisma.$disconnect();
|
||||
process.exit(0);
|
||||
});
|
||||
if (process.env.NODE_ENV === 'production' && !process.env.NEXT_PHASE) {
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('Received SIGINT signal. Closing database connections...');
|
||||
await prisma.$disconnect();
|
||||
// Allow natural exit
|
||||
});
|
||||
|
||||
process.on('SIGTERM', async () => {
|
||||
console.log('Received SIGTERM signal. Closing database connections...');
|
||||
await prisma.$disconnect();
|
||||
process.exit(0);
|
||||
});
|
||||
process.on('SIGTERM', async () => {
|
||||
console.log('Received SIGTERM signal. Closing database connections...');
|
||||
await prisma.$disconnect();
|
||||
// Allow natural exit
|
||||
});
|
||||
}
|
||||
|
||||
export default prisma;
|
||||
Reference in New Issue
Block a user