last update
This commit is contained in:
+16
-21
@@ -1,8 +1,8 @@
|
||||
import Content from "@/components/dashboard/Content";
|
||||
import { defineAbilitiesFor, fetchReq } from "@/lib/ability";
|
||||
import { defineAbilitiesFor } from "@/lib/ability";
|
||||
import { getUser } from "@/lib/auth";
|
||||
import { getStateInfo } from "@/lib/getStateInfo";
|
||||
import axios from "axios";
|
||||
import { fetchReq } from "@/lib/req";
|
||||
import { cookies, headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
@@ -12,36 +12,31 @@ export default async function Dashboard({ searchParams }) {
|
||||
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");
|
||||
}
|
||||
const userInfo = cookieStore.get("userInfo");
|
||||
console.log(userInfo.value.uuid);
|
||||
|
||||
if (!ability.can("access", "Dashboard")) {
|
||||
return redirect("/");
|
||||
}
|
||||
|
||||
const response = await fetchReq(
|
||||
`https://back-dev.clinic-pro.ir/api/v1/user-profile/${userInfo.value.uuid}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token.value}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((res) => console.log(res))
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
const userAgent = headers().get("user-agent") || "";
|
||||
const isMobile = /Mobi|Android/i.test(userAgent);
|
||||
|
||||
return (
|
||||
<Content
|
||||
dataUser={response}
|
||||
logged={token.value}
|
||||
dataUser={dashboard}
|
||||
params={searchParams}
|
||||
matchedCity={matchedCity}
|
||||
initialTurnsDetails={isMobile}
|
||||
|
||||
Reference in New Issue
Block a user