en replaced with defalutLocale cookie

This commit is contained in:
parsa aghaei 2024-10-23 19:05:31 +03:30
parent fb89647a32
commit 80016bc39a
3 changed files with 6 additions and 5 deletions

View File

@ -6,7 +6,7 @@ import "react-loading-skeleton/dist/skeleton.css";
export default async function AboutMe() { export default async function AboutMe() {
const aboutMeData: AboutMeDataType = await fetch( const aboutMeData: AboutMeDataType = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/website/about-me/1/translation/${cookies().get("selectedLocale")?.value}`, `${process.env.NEXT_PUBLIC_API_URL}/website/about-me/1/translation/${cookies().get("selectedLocale")?.value ? cookies().get("selectedLocale")?.value : cookies().get("defaultLocale")?.value}`,
).then((res) => res.json()); ).then((res) => res.json());
return ( return (

View File

@ -24,11 +24,12 @@ export default function Services({ dict }: ServicesProps) {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
useEffect(() => { useEffect(() => {
const fetchServices = async () => { const fetchServices = async () => {
setLoading(true); setLoading(true);
const response = await fetch( const response = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/website/services/${getCookie("selectedLocale")}`, `${process.env.NEXT_PUBLIC_API_URL}/website/services/${getCookie("selectedLocale") !== undefined ? getCookie("selectedLocale") : getCookie("defaultLocale")}`,
).then((res) => res.json()); ).then((res) => res.json());
setServices(response); setServices(response);

View File

@ -45,12 +45,12 @@ export function middleware(request: NextRequest) {
if (selectedLocale && selectedLocale.value !== "") { if (selectedLocale && selectedLocale.value !== "") {
response.cookies.set("defaultLocale", selectedLocale.value, { response.cookies.set("defaultLocale", selectedLocale.value, {
path: "/", path: "/",
httpOnly: true, httpOnly: false,
}); });
} else { } else {
response.cookies.set("defaultLocale", defaultLocale, { response.cookies.set("defaultLocale", defaultLocale, {
path: "/", path: "/",
httpOnly: true, httpOnly: false,
}); });
} }