Files
nobat724_front/app/panel/(layout)/layout.js
T
hamed 194ffd889c feat: enhance security by implementing HttpOnly refresh tokens and in-memory access token management
- Added isomorphic-dompurify for improved XSS protection
- Refactored token storage to use in-memory management for access tokens
- Implemented server-side route handlers for OAuth token management
- Introduced security headers in next.config.js
- Removed client-side exposure of client_secret and sensitive tokens
- Updated API interceptors to handle token refresh logic
- Cleaned up cookie management for refresh tokens
2026-06-20 13:10:17 +03:30

52 lines
1.5 KiB
JavaScript

import Content from "@/components/panel/Content";
import { defineAbilitiesFor } from "@/lib/ability";
import { getUser } from "@/lib/auth";
import { redirect } from "next/navigation";
import { cookies } from "next/headers";
import { fetchReq } from "@/lib/req";
import { safeJsonParse } from "@/lib/sanitize";
import { getServerAccessToken } from "@/lib/serverToken";
async function LayoutPanel({ children }) {
const user = await getUser();
const ability = defineAbilitiesFor(user);
if (!ability.can("access", "Panel")) {
return redirect("/");
}
let representationInfo = null;
const API_URL = process.env.NEXT_PUBLIC_API_URL;
try {
const cookieStore = await cookies();
const userInfo = cookieStore.get("userInfo");
if (userInfo) {
const parsedUserInfo = safeJsonParse(userInfo.value);
if (!parsedUserInfo) return;
const representationUuid = parsedUserInfo?.representation_uuid;
if (representationUuid) {
const accessToken = await getServerAccessToken();
if (accessToken) {
representationInfo = await fetchReq(
`${API_URL}/api/v1/representation/${representationUuid}`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
);
}
}
}
} catch (error) {
console.error("Error fetching representation info:", error);
}
return <Content children={children} representationInfo={representationInfo} />;
}
export default LayoutPanel;