51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import Content from "@/components/dashboard/Content";
|
|
import { defineAbilitiesFor, fetchReq } from "@/lib/ability";
|
|
import { getUser } from "@/lib/auth";
|
|
import { getStateInfo } from "@/lib/getStateInfo";
|
|
import axios from "axios";
|
|
import { cookies, headers } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
|
|
export default async function Dashboard({ searchParams }) {
|
|
const { matchedCity } = getStateInfo();
|
|
const user = await getUser();
|
|
const ability = defineAbilitiesFor(user);
|
|
const cookieStore = cookies();
|
|
const token = cookieStore.get("access_token");
|
|
const uuid = cookieStore.get("uuid");
|
|
|
|
let dashboard = null;
|
|
try {
|
|
const response = await fetchReq(
|
|
`https://back-dev.clinic-pro.ir/api/v1/user-profile/${uuid}`,
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
}
|
|
);
|
|
|
|
dashboard = response.data;
|
|
} catch (error) {
|
|
// console.error("problem with req:", error.message);
|
|
// return redirect("/unauthorized");
|
|
}
|
|
|
|
if (!ability.can("access", "Dashboard")) {
|
|
return redirect("/");
|
|
}
|
|
|
|
const userAgent = headers().get("user-agent") || "";
|
|
const isMobile = /Mobi|Android/i.test(userAgent);
|
|
|
|
return (
|
|
<Content
|
|
logged={token.value}
|
|
dataUser={dashboard}
|
|
params={searchParams}
|
|
matchedCity={matchedCity}
|
|
initialTurnsDetails={isMobile}
|
|
/>
|
|
);
|
|
}
|