diff --git a/src/features/auth/ui/AuthLoginFormUi/AuthLoginFormUi.tsx b/src/features/auth/ui/AuthLoginFormUi/AuthLoginFormUi.tsx index cb528a6..ce2c341 100644 --- a/src/features/auth/ui/AuthLoginFormUi/AuthLoginFormUi.tsx +++ b/src/features/auth/ui/AuthLoginFormUi/AuthLoginFormUi.tsx @@ -1,6 +1,7 @@ import React from "react"; import { ButtonUi, ButtonUiType } from "../../../../shared/UI/ButtonUi"; +import { useNavigate } from "react-router-dom"; import Form from 'react-bootstrap/Form'; @@ -14,6 +15,8 @@ import styles from "./authLoginForm.module.scss"; export const AuthLoginFormUi = () => { + const navigate = useNavigate() + const schema = yup.object().shape({ username: yup.string() .min(3, 'Минимум 3 символа!') @@ -47,7 +50,7 @@ export const AuthLoginFormUi = () => { } else { setCookie('authToken', res.data!.authToken) setCookie('refreshToken', res.data!.refreshToken) - window.location.replace("/auction") + navigate('/auction') } return res.data as AuthResponsePayload }) diff --git a/src/query/query.ts b/src/query/query.ts index 3aec9ec..db10894 100644 --- a/src/query/query.ts +++ b/src/query/query.ts @@ -6,10 +6,14 @@ export const api = axios.create({ headers: { accept: 'application/json', 'Content-Type': 'application/json', - 'Authorization': getCookie('authToken') ? `Bearer ${getCookie('authToken')}` : '' }, }) +api.interceptors.request.use(config => { + config.headers.authorization = getCookie('authToken') ? `Bearer ${getCookie('authToken')}` : '' + return config +}) + api.interceptors.response.use(undefined, async function (error) { if (error?.response?.status === 401) { removeCookie('authToken')