deskripsi:
- fix next.config.
- penambahan force-dynamic
- new route: src/app/api/user/id/
No Issuee
This commit is contained in:
2025-05-22 15:40:09 +08:00
parent 37fb25715e
commit 1d04b05fe7
5 changed files with 91 additions and 10 deletions

View File

@@ -4,10 +4,24 @@ const nextConfig = {
experimental: {
serverActions: true,
},
// output: "standalone",
output: "standalone",
// eslint: {
// ignoreDuringBuilds: true,
// },
async headers() {
return [
{
source: "/(.*)",
headers: [
{
key: "Cache-Control",
value: "no-store, max-age=0",
},
],
},
];
},
};
module.exports = nextConfig;

View File

@@ -0,0 +1,49 @@
import { NextResponse } from 'next/server';
import { cookies } from "next/headers";
import { decrypt } from "@/app/(auth)/_lib/decrypt";
export async function GET() {
const SESSION_KEY = process.env.NEXT_PUBLIC_BASE_SESSION_KEY;
if (!SESSION_KEY) {
return NextResponse.json(
{ success: false, error: "Session key not configured" },
{ status: 500 }
);
}
const cookieStore = cookies();
const token = cookieStore.get(SESSION_KEY)?.value;
if (!token) {
return NextResponse.json(
{ success: false, error: "No token found" },
{ status: 401 }
);
}
try {
const decoded = await decrypt({
token,
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
});
if (!decoded) {
return NextResponse.json(
{ success: false, error: "Invalid token" },
{ status: 401 }
);
}
return NextResponse.json({
success: true,
userId: decoded.id,
});
} catch (error) {
console.error("Error decoding token:", error);
return NextResponse.json(
{ success: false, error: "Failed to decode token" },
{ status: 500 }
);
}
}

View File

@@ -4,6 +4,8 @@ import { Colab_GroupChatView } from "@/app_modules/colab";
import colab_getMessageByRoomId from "@/app_modules/colab/fun/get/room_chat/get_message_by_room_id";
import { user_getOneByUserId } from "@/app_modules/home/fun/get/get_one_user_by_id";
import _ from "lodash";
export const dynamic = "force-dynamic";
export default async function Page({ params }: { params: { id: string } }) {
const roomId = params.id;

View File

@@ -1,13 +1,13 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { RealtimeProvider } from "../../lib";
import { ServerEnv } from "../../lib/server_env";
export const dynamic = "force-dynamic";
export default async function Layout({
children,
}: {
children: React.ReactNode;
}) {
const userId = await funGetUserIdByToken();
return (

View File

@@ -4,14 +4,30 @@ import { cookies } from "next/headers";
import { decrypt } from "../../../../app/(auth)/_lib/decrypt";
export async function funGetUserIdByToken() {
const SESSION_KEY = process.env.NEXT_PUBLIC_BASE_SESSION_KEY!;
const c = cookies().get(SESSION_KEY);
const SESSION_KEY = process.env.NEXT_PUBLIC_BASE_SESSION_KEY;
const cekUser = await decrypt({
token: c?.value as string,
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
});
if (!SESSION_KEY) {
console.warn("SESSION_KEY tidak ditemukan");
return null;
}
return cekUser?.id;
const cookieStore = cookies();
const c = cookieStore.get(SESSION_KEY);
if (!c?.value) {
console.warn("Cookie tidak ditemukan");
return null;
}
try {
const cekUser = await decrypt({
token: c.value,
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
});
return cekUser?.id || null;
} catch (error) {
console.error("Gagal mendekripsi token:", error);
return null;
}
}