diff --git a/next.config.js b/next.config.js index 56826594..66e268d2 100644 --- a/next.config.js +++ b/next.config.js @@ -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; diff --git a/src/app/api/user/id/route.ts b/src/app/api/user/id/route.ts new file mode 100644 index 00000000..25add98e --- /dev/null +++ b/src/app/api/user/id/route.ts @@ -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 } + ); + } +} diff --git a/src/app/dev/(user)/colab/detail/group/[id]/page.tsx b/src/app/dev/(user)/colab/detail/group/[id]/page.tsx index ebd48b78..83ee477b 100644 --- a/src/app/dev/(user)/colab/detail/group/[id]/page.tsx +++ b/src/app/dev/(user)/colab/detail/group/[id]/page.tsx @@ -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; diff --git a/src/app/dev/layout.tsx b/src/app/dev/layout.tsx index 4eeae49d..6ad7f4a8 100644 --- a/src/app/dev/layout.tsx +++ b/src/app/dev/layout.tsx @@ -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 ( diff --git a/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts b/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts index 3164efdf..6bc4b6c2 100644 --- a/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts +++ b/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts @@ -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; + } } -