API Table Forum Posting & API Table Forum Report Komentar

This commit is contained in:
2025-02-10 17:15:01 +08:00
25 changed files with 412 additions and 357 deletions

View File

@@ -1,6 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
import { jwtVerify } from "jose";
import { apies, pages } from "./lib/routes";
import { NextRequest, NextResponse } from "next/server";
type MiddlewareConfig = {
apiPath: string;
@@ -111,7 +110,7 @@ export const middleware = async (req: NextRequest) => {
// Preserve token in cookie when redirecting
if (token) {
response.cookies.set(sessionKey, token, {
httpOnly: true,
// httpOnly: true,
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
path: "/",
@@ -146,6 +145,19 @@ export const middleware = async (req: NextRequest) => {
const userValidateJson = await userValidate.json();
if (userValidateJson.success == true && userValidateJson.data == null) {
const logout = await fetch(new URL("/api/auth/logout", req.url), {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
});
if (!logout.ok) {
throw new Error("Failed to logout user");
}
}
if (!userValidateJson.data.active) {
return setCorsHeaders(
NextResponse.redirect(new URL("/waiting-room", req.url))
@@ -187,7 +199,7 @@ export const middleware = async (req: NextRequest) => {
// Ensure token is preserved in cookie
if (token) {
response.cookies.set(sessionKey, token, {
httpOnly: true,
// httpOnly: true,
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
path: "/",