diff --git a/src/hooks/useAxios.ts b/src/hooks/useAxios.ts index 792da85..6ebc0fb 100644 --- a/src/hooks/useAxios.ts +++ b/src/hooks/useAxios.ts @@ -10,6 +10,11 @@ const useAxios = () => { const instance = axios.create({ baseURL: "https://api.persain-game.com/api/v1", maxBodyLength: Infinity, + ...(sessionStorage.getItem("shop_id") && { + headers: { + "Shop-ID": sessionStorage.getItem("shop_id"), + }, + }), }); instance.interceptors.request.use( diff --git a/src/layout/index.tsx b/src/layout/index.tsx index 2bc1339..2590712 100644 --- a/src/layout/index.tsx +++ b/src/layout/index.tsx @@ -1,4 +1,4 @@ -import { Outlet, useParams } from "react-router-dom"; +import { Outlet, useNavigate, useParams } from "react-router-dom"; import Header from "../components/header"; import Footer from "../components/footer"; import Particle from "../components/particle"; @@ -11,7 +11,7 @@ import { setShopId } from "../redux/slices/shop-id"; const Layout = () => { const { configs } = useParams<{ configs: string }>(); - + const navigate = useNavigate(); const shopId = new URLSearchParams(window.location.search).get("shop_id"); const dispatch = useDispatch(); @@ -33,6 +33,7 @@ const Layout = () => { useEffect(() => { if (shopId) { dispatch(setShopId(shopId)); + navigate("/"); } }, [shopId, dispatch]); diff --git a/src/redux/slices/shop-id.ts b/src/redux/slices/shop-id.ts index 6e56f77..80406f9 100644 --- a/src/redux/slices/shop-id.ts +++ b/src/redux/slices/shop-id.ts @@ -17,6 +17,7 @@ const shopIdSlice = createSlice({ reducers: { setShopId: (state, action: PayloadAction) => { state.shop_id = action.payload; + sessionStorage.setItem("shop_id", action.payload); }, }, });