Files
nobat724_front/components/register/verificationPage/SendReq.js
T
hamedandClaude Sonnet 4.6 1aa9f82d2a 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>
2026-06-05 22:18:11 +03:30

121 lines
2.8 KiB
JavaScript

import { Button } from "@mui/material";
import { request } from "@/services/response";
import Cookies from "js-cookie";
import { handleTimeExpiresToken } from "@/helper";
function SendReq({
loading,
setLoading,
code,
setIsSendMsg,
setStep,
setIsError,
uuid,
}) {
const handleReq = async () => {
setLoading(true);
try {
const res = await fetch("/api/auth/token", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ uuid, code: code.join("") }),
});
const response = await res.json();
if (response.access_token) {
handleSetCookie(response);
} else {
setLoading(false);
setIsError(true);
}
} catch {
setLoading(false);
setIsError(true);
}
};
const handleSetCookie = (response) => {
const expiresTime = handleTimeExpiresToken(response.expires_in);
const hostname = window.location.hostname;
const isHttps = window.location.protocol === "https:";
const isLocalhost = hostname.includes("localhost");
// تنظیمات پایه
let cookieOptions = {
path: "/",
sameSite: "lax",
expires: expiresTime.accessTokenExpires,
};
// اگر روی دامنه اصلی و https بود
if (!isLocalhost && isHttps) {
cookieOptions = {
...cookieOptions,
secure: true,
domain: ".nobat724.com",
};
}
Cookies.set("access_token", response.access_token, cookieOptions);
Cookies.set("refresh_token", response.refresh_token, {
...cookieOptions,
expires: expiresTime.refreshTokenExpires,
});
Cookies.set("uuid", uuid, {
...cookieOptions,
expires: expiresTime.refreshTokenExpires,
});
getInfo(response.access_token, cookieOptions);
};
const getInfo = (token, cookieOptions) => {
request
.getUserInfo({
headers: {
Authorization: `Bearer ${token}`,
},
})
.then((res) => {
setLoading(false);
if (res && res.uuid) {
Cookies.set("userInfo", JSON.stringify(res), cookieOptions);
// اگر در صفحه appointment هستیم، به مرحله 3 (Detail) می‌رویم
if (setStep) {
setStep(3);
} else {
window.location.pathname = "/";
}
}
})
.catch(() => {
setLoading(false);
setIsError(true);
});
};
return (
<Button
fullWidth
disabled={loading}
variant="contained"
onClick={() => {
setIsSendMsg && setIsSendMsg(true);
if (code.join("").length !== 5) {
setIsError(true);
} else {
handleReq();
}
}}
className="!rounded-[8px] !bg-[#5559CE]"
>
تایید
</Button>
);
}
export default SendReq;