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,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;
}
}