forked from Transparency/kgroad-frontend2
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import Typography from "@/shared/ui/components/Typography/Typography";
|
||
import "./Profile.scss";
|
||
import ProfileNav from "@/widgets/ProfileNav/ProfileNav";
|
||
import AuthGuard from "./AuthGuard";
|
||
import { AxiosError } from "axios";
|
||
import { apiInstance } from "@/shared/config/apiConfig";
|
||
import { getServerSession } from "next-auth";
|
||
import { authConfig } from "@/shared/config/authConfig";
|
||
import { Metadata } from "next";
|
||
|
||
export const metadata: Metadata = {
|
||
title: "KG ROAD | Профиль",
|
||
description:
|
||
"Страница профиля Kyrgyzstan Transperency International",
|
||
};
|
||
|
||
const Profile = async ({
|
||
children,
|
||
}: Readonly<{
|
||
children: React.ReactNode;
|
||
}>) => {
|
||
const session = await getServerSession(authConfig);
|
||
|
||
const getProfile = async () => {
|
||
const Authorization = `Bearer ${session?.access_token}`;
|
||
const config = {
|
||
headers: {
|
||
Authorization,
|
||
},
|
||
};
|
||
try {
|
||
const response = await apiInstance.get<{
|
||
report_count: number;
|
||
}>("/users/profile/", config);
|
||
|
||
return response.data;
|
||
} catch (error: unknown) {
|
||
if (error instanceof AxiosError) console.log(error.message);
|
||
}
|
||
};
|
||
|
||
const data = await getProfile();
|
||
|
||
return (
|
||
<div className="profile page-padding">
|
||
<Typography element="h2">Личный кабинет</Typography>
|
||
<ProfileNav report_count={data?.report_count as number} />
|
||
|
||
<AuthGuard>{children}</AuthGuard>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default Profile;
|