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

@@ -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 }
);
}
}