last update
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import BlogPage from "@/components/blog";
|
import BlogPage from "@/components/blog";
|
||||||
import Layout from "@/components/layout/StLayout";
|
import Layout from "@/components/layout/StLayout";
|
||||||
import { fetchReq } from "@/lib/ability";
|
import { fetchReq } from "@/lib/req";
|
||||||
|
|
||||||
async function Blog({ params: { slug } }) {
|
async function Blog({ params: { slug } }) {
|
||||||
const blog = await fetchReq(
|
const blog = await fetchReq(
|
||||||
@@ -8,12 +8,9 @@ async function Blog({ params: { slug } }) {
|
|||||||
);
|
);
|
||||||
const blogs = await fetchReq("https://back-dev.clinic-pro.ir/api/v1/blogs");
|
const blogs = await fetchReq("https://back-dev.clinic-pro.ir/api/v1/blogs");
|
||||||
|
|
||||||
const resBlog = blog;
|
|
||||||
const resBlogs = blogs;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<BlogPage blog={resBlog} blogs={resBlogs.blogs} />
|
<BlogPage blog={blog} blogs={blogs.blogs} />
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import BlogsPage from "@/components/blogs";
|
import BlogsPage from "@/components/blogs";
|
||||||
import Layout from "@/components/layout/StLayout";
|
import Layout from "@/components/layout/StLayout";
|
||||||
import { fetchReq } from "@/lib/ability";
|
import { fetchReq } from "@/lib/req";
|
||||||
|
|
||||||
export default async function Blogs() {
|
export default async function Blogs() {
|
||||||
const response = await fetchReq(
|
const response = await fetchReq(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import ClinicPage from "@/components/clinic";
|
import ClinicPage from "@/components/clinic";
|
||||||
import Layout from "@/components/layout/StLayout";
|
import Layout from "@/components/layout/StLayout";
|
||||||
import { fetchReq } from "@/lib/ability";
|
import { fetchReq } from "@/lib/req";
|
||||||
|
|
||||||
async function Clinic({ params: { slug } }) {
|
async function Clinic({ params: { slug } }) {
|
||||||
const reqClinics = await fetchReq(
|
const reqClinics = await fetchReq(
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// app/clinics/page.js
|
// app/clinics/page.js
|
||||||
import ClinicsPage from "@/components/clinics";
|
import ClinicsPage from "@/components/clinics";
|
||||||
import Layout from "@/components/layout/StLayout";
|
import Layout from "@/components/layout/StLayout";
|
||||||
import { fetchReq } from "@/lib/ability";
|
import { fetchReq } from "@/lib/req";
|
||||||
import { getStateInfo } from "@/lib/getStateInfo";
|
import { getStateInfo } from "@/lib/getStateInfo";
|
||||||
|
|
||||||
export default async function Clinics() {
|
export default async function Clinics() {
|
||||||
|
|||||||
+16
-21
@@ -1,8 +1,8 @@
|
|||||||
import Content from "@/components/dashboard/Content";
|
import Content from "@/components/dashboard/Content";
|
||||||
import { defineAbilitiesFor, fetchReq } from "@/lib/ability";
|
import { defineAbilitiesFor } from "@/lib/ability";
|
||||||
import { getUser } from "@/lib/auth";
|
import { getUser } from "@/lib/auth";
|
||||||
import { getStateInfo } from "@/lib/getStateInfo";
|
import { getStateInfo } from "@/lib/getStateInfo";
|
||||||
import axios from "axios";
|
import { fetchReq } from "@/lib/req";
|
||||||
import { cookies, headers } from "next/headers";
|
import { cookies, headers } from "next/headers";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
@@ -12,36 +12,31 @@ export default async function Dashboard({ searchParams }) {
|
|||||||
const ability = defineAbilitiesFor(user);
|
const ability = defineAbilitiesFor(user);
|
||||||
const cookieStore = cookies();
|
const cookieStore = cookies();
|
||||||
const token = cookieStore.get("access_token");
|
const token = cookieStore.get("access_token");
|
||||||
const uuid = cookieStore.get("uuid");
|
const userInfo = cookieStore.get("userInfo");
|
||||||
|
console.log(userInfo.value.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")) {
|
if (!ability.can("access", "Dashboard")) {
|
||||||
return redirect("/");
|
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 userAgent = headers().get("user-agent") || "";
|
||||||
const isMobile = /Mobi|Android/i.test(userAgent);
|
const isMobile = /Mobi|Android/i.test(userAgent);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Content
|
<Content
|
||||||
|
dataUser={response}
|
||||||
logged={token.value}
|
logged={token.value}
|
||||||
dataUser={dashboard}
|
|
||||||
params={searchParams}
|
params={searchParams}
|
||||||
matchedCity={matchedCity}
|
matchedCity={matchedCity}
|
||||||
initialTurnsDetails={isMobile}
|
initialTurnsDetails={isMobile}
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ async function Doctors({ searchParams }) {
|
|||||||
const response = await axios.get(
|
const response = await axios.get(
|
||||||
"https://back-dev.clinic-pro.ir/api/v1/doctors"
|
"https://back-dev.clinic-pro.ir/api/v1/doctors"
|
||||||
);
|
);
|
||||||
console.log(response);
|
|
||||||
|
|
||||||
doctors = response.data.$data;
|
doctors = response.data.$data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.error("problem with req:", error.message);
|
// console.error("problem with req:", error.message);
|
||||||
|
|||||||
+11
-1
@@ -1,6 +1,16 @@
|
|||||||
import ContentLogin from "@/components/register/ContentLogin";
|
import ContentLogin from "@/components/register/ContentLogin";
|
||||||
|
import { defineAbilitiesFor } from "@/lib/ability";
|
||||||
|
import { getUser } from "@/lib/auth";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
|
async function LogIn() {
|
||||||
|
const user = await getUser();
|
||||||
|
const ability = defineAbilitiesFor(user);
|
||||||
|
|
||||||
|
if (!ability.can("access", "Login")) {
|
||||||
|
return redirect("/");
|
||||||
|
}
|
||||||
|
|
||||||
function LogIn() {
|
|
||||||
return <ContentLogin />;
|
return <ContentLogin />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ function Content({ matchedCity, params, logged, initialIsOpenSide, dataUser }) {
|
|||||||
const [value, setValue] = useState(Number(params?.sidebar) || 0);
|
const [value, setValue] = useState(Number(params?.sidebar) || 0);
|
||||||
const [isOpenSide, setIsOpenSide] = useState(initialIsOpenSide);
|
const [isOpenSide, setIsOpenSide] = useState(initialIsOpenSide);
|
||||||
const [isTurnsDetails, setIsTurnsDetails] = useState(false);
|
const [isTurnsDetails, setIsTurnsDetails] = useState(false);
|
||||||
|
console.log(dataUser);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardPage
|
<DashboardPage
|
||||||
|
|||||||
@@ -11,6 +11,24 @@ function SendReq({
|
|||||||
setIsError,
|
setIsError,
|
||||||
uuid,
|
uuid,
|
||||||
}) {
|
}) {
|
||||||
|
const handleReq = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
request
|
||||||
|
.getToken(
|
||||||
|
"mobile",
|
||||||
|
process.env.NEXT_PUBLIC_CLIENT_ID,
|
||||||
|
process.env.NEXT_PUBLIC_CLIENT_SECRET,
|
||||||
|
uuid,
|
||||||
|
code.join("")
|
||||||
|
)
|
||||||
|
.then((response) => {
|
||||||
|
if (response.access_token) {
|
||||||
|
handleSetCookie(response);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
};
|
||||||
|
|
||||||
const handleSetCookie = (response) => {
|
const handleSetCookie = (response) => {
|
||||||
const accessTokenExpires = new Date();
|
const accessTokenExpires = new Date();
|
||||||
accessTokenExpires.setSeconds(
|
accessTokenExpires.setSeconds(
|
||||||
@@ -39,28 +57,28 @@ function SendReq({
|
|||||||
secure: true,
|
secure: true,
|
||||||
sameSite: "strict",
|
sameSite: "strict",
|
||||||
});
|
});
|
||||||
|
getInfo(response.access_token);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReq = async () => {
|
const getInfo = (token) => {
|
||||||
setLoading(true);
|
|
||||||
request
|
request
|
||||||
.getToken(
|
.getUserInfo({
|
||||||
"mobile",
|
headers: {
|
||||||
process.env.NEXT_PUBLIC_CLIENT_ID,
|
Authorization: `Bearer ${token}`,
|
||||||
process.env.NEXT_PUBLIC_CLIENT_SECRET,
|
},
|
||||||
uuid,
|
})
|
||||||
code.join("")
|
.then((res) => {
|
||||||
)
|
|
||||||
.then((response) => {
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
if (response.access_token) {
|
if (res && res.uuid) {
|
||||||
window.location.pathname = "/";
|
window.location.pathname = "/";
|
||||||
handleSetCookie(response);
|
Cookies.set("userInfo", JSON.stringify(res), {
|
||||||
|
path: "/",
|
||||||
|
secure: true,
|
||||||
|
sameSite: "strict",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {});
|
||||||
setLoading(false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+2
-15
@@ -1,28 +1,15 @@
|
|||||||
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
||||||
import axios from "axios";
|
|
||||||
import Cookies from "js-cookie";
|
|
||||||
|
|
||||||
const token = Cookies.get("access_token");
|
|
||||||
|
|
||||||
export function defineAbilitiesFor(user) {
|
export function defineAbilitiesFor(user) {
|
||||||
const { can, cannot, build } = new AbilityBuilder(createMongoAbility);
|
const { can, cannot, build } = new AbilityBuilder(createMongoAbility);
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
can("access", "Dashboard");
|
can("access", "Dashboard");
|
||||||
|
cannot("access", "Login");
|
||||||
} else {
|
} else {
|
||||||
// can("access", "Dashboard");
|
can("access", "Login");
|
||||||
cannot("access", "Dashboard");
|
cannot("access", "Dashboard");
|
||||||
}
|
}
|
||||||
|
|
||||||
return build();
|
return build();
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchReq = async (url, headers) => {
|
|
||||||
try {
|
|
||||||
const response = await axios.get(url, headers);
|
|
||||||
return response.data;
|
|
||||||
} catch (error) {
|
|
||||||
console.error("fetchReq error:", error.message);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
export const fetchReq = async (url, headers) => {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(url, headers);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("fetchReq error:", error.message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -33,4 +33,5 @@ export const request = {
|
|||||||
postUserProfile: (data) => api.post("api/v1/user-profile", data),
|
postUserProfile: (data) => api.post("api/v1/user-profile", data),
|
||||||
patchUserProfile: (data, uuid) =>
|
patchUserProfile: (data, uuid) =>
|
||||||
api.patch(`api/v1/user-profile/${uuid}`, data),
|
api.patch(`api/v1/user-profile/${uuid}`, data),
|
||||||
|
getUserInfo: (headers) => api.get("oauth/userinfo", headers),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const removeToken = () => {
|
|||||||
Cookies.remove("access_token", { path: "/" });
|
Cookies.remove("access_token", { path: "/" });
|
||||||
Cookies.remove("refresh_token", { path: "/" });
|
Cookies.remove("refresh_token", { path: "/" });
|
||||||
Cookies.remove("uuid", { path: "/" });
|
Cookies.remove("uuid", { path: "/" });
|
||||||
|
Cookies.remove("userInfo", { path: "/" });
|
||||||
};
|
};
|
||||||
|
|
||||||
export { removeToken };
|
export { removeToken };
|
||||||
|
|||||||
Reference in New Issue
Block a user