fix: resolve critical bugs and security issues across the project
- Fix GPS map links always sending literal "latitude"/"longitude" strings instead of actual coordinates in openLocation/Content.js - Add api.clinic-pro.ir to next.config.js remotePatterns so production images load correctly - Fix appointment page: await params and getStateInfo (Next.js 15 pattern) - Enable 401 handling in api.js: clear cookies and redirect to /login - Move OAuth client_secret to server-side API routes (/api/auth/token, /api/auth/refresh) so it is never bundled into client-side JavaScript - Update SendReq, SubmitData, ButtonSendData to call API routes instead of directly sending client_secret from the browser - Update docker-compose.yml to use server-only CLIENT_SECRET env var - Remove debug console.log from clinic doctors list component Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
ec536bfc32
commit
1aa9f82d2a
@@ -0,0 +1,31 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function POST(request) {
|
||||
const { refresh_token } = await request.json();
|
||||
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
const CLIENT_ID = process.env.CLIENT_ID || process.env.NEXT_PUBLIC_CLIENT_ID;
|
||||
const CLIENT_SECRET = process.env.CLIENT_SECRET || process.env.NEXT_PUBLIC_CLIENT_SECRET;
|
||||
|
||||
if (!refresh_token) {
|
||||
return NextResponse.json({ error: "refresh_token is required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const formData = new URLSearchParams();
|
||||
formData.append("grant_type", "refresh_token");
|
||||
formData.append("client_id", CLIENT_ID);
|
||||
formData.append("client_secret", CLIENT_SECRET);
|
||||
formData.append("refresh_token", refresh_token);
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/oauth/token`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: "" },
|
||||
body: formData.toString(),
|
||||
});
|
||||
const data = await res.json();
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Refresh request failed" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function POST(request) {
|
||||
const { uuid, code, scope = "nobat724" } = await request.json();
|
||||
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
const CLIENT_ID = process.env.CLIENT_ID || process.env.NEXT_PUBLIC_CLIENT_ID;
|
||||
const CLIENT_SECRET = process.env.CLIENT_SECRET || process.env.NEXT_PUBLIC_CLIENT_SECRET;
|
||||
|
||||
if (!uuid || !code) {
|
||||
return NextResponse.json({ error: "uuid and code are required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const formData = new URLSearchParams();
|
||||
formData.append("grant_type", "mobile");
|
||||
formData.append("client_id", CLIENT_ID);
|
||||
formData.append("client_secret", CLIENT_SECRET);
|
||||
formData.append("uuid", uuid);
|
||||
formData.append("code", code);
|
||||
formData.append("scope", scope);
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/oauth/token`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: "" },
|
||||
body: formData.toString(),
|
||||
});
|
||||
const data = await res.json();
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Token request failed" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -2,33 +2,26 @@ import AppointmentPage from "@/components/appointment";
|
||||
import { getStateInfo } from "@/lib/getStateInfo";
|
||||
import axios from "axios";
|
||||
|
||||
async function Appointment({ params: { doctorId } }) {
|
||||
const { matchedCity } = getStateInfo();
|
||||
async function Appointment({ params }) {
|
||||
const { doctorId } = await params;
|
||||
const { matchedCity } = await getStateInfo();
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
|
||||
let doctor = null;
|
||||
let disabledDates = [];
|
||||
|
||||
try {
|
||||
// دریافت اطلاعات دکتر با UUID
|
||||
const doctorRes = await axios.get(`${API_URL}/api/v1/doctor/${doctorId}`);
|
||||
doctor = doctorRes.data;
|
||||
|
||||
// دریافت روزهای غیرفعال با استفاده از doctor.id
|
||||
if (doctor && doctor.id) {
|
||||
const disabledDatesRes = await axios.get(
|
||||
`${API_URL}/api/v1/appointment/not-available/${doctor.id}`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
{ headers: { "Content-Type": "application/json" } }
|
||||
);
|
||||
disabledDates = disabledDatesRes.data?.data || [];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching appointment data:", error.message);
|
||||
}
|
||||
} catch (error) {}
|
||||
|
||||
return (
|
||||
<AppointmentPage
|
||||
|
||||
@@ -8,27 +8,27 @@ function Content({ data, onClose }) {
|
||||
{
|
||||
src: "/assets/images/snapp.png",
|
||||
name: "snapp",
|
||||
url: `https://snapp.ir/route?lat=${"latitude"}&lng=${"longitude"}`,
|
||||
url: `https://snapp.ir/route?lat=${latitude}&lng=${longitude}`,
|
||||
},
|
||||
{
|
||||
src: "/assets/images/tapsi.png",
|
||||
name: "tapsi",
|
||||
url: `https://tapsi.ir/route?lat=${"latitude"}&lng=${"longitude"}`,
|
||||
url: `https://tapsi.ir/route?lat=${latitude}&lng=${longitude}`,
|
||||
},
|
||||
{
|
||||
src: "/assets/images/maps.png",
|
||||
name: "maps",
|
||||
url: `https://www.google.com/maps/dir/?api=1&destination=${"latitude"},${"longitude"}`,
|
||||
url: `https://www.google.com/maps/dir/?api=1&destination=${latitude},${longitude}`,
|
||||
},
|
||||
{
|
||||
src: "/assets/images/balad.png",
|
||||
name: "balad",
|
||||
url: `https://balad.ir/map?lat=${"latitude"}&lng=${"longitude"}`,
|
||||
url: `https://balad.ir/map?lat=${latitude}&lng=${longitude}`,
|
||||
},
|
||||
{
|
||||
src: "/assets/images/waze.png",
|
||||
name: "waze",
|
||||
url: `https://waze.com/ul?ll=${"latitude"},${"longitude"}&navigate=yes`,
|
||||
url: `https://waze.com/ul?ll=${latitude},${longitude}&navigate=yes`,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user