bearer для токена
This commit is contained in:
parent
c251a598cc
commit
9cb2548603
@ -5,6 +5,7 @@ import { authStore } from "@root/stores/auth";
|
||||
const PublicRoute = ({ children }: any) => {
|
||||
const location = useLocation();
|
||||
const { token } = authStore();
|
||||
console.log(token)
|
||||
|
||||
if (token) {
|
||||
return <Navigate to="/users" state={{ from: location }} />;
|
||||
|
@ -16,8 +16,16 @@ import ClearIcon from "@mui/icons-material/Clear";
|
||||
import { getRoles_mock, TMockData } from "../../../api/roles";
|
||||
import theme from "../../../theme";
|
||||
import axios from "axios";
|
||||
import {authStore} from "@stores/auth";
|
||||
|
||||
const Users: React.FC = () => {
|
||||
const { makeRequest } = authStore();
|
||||
makeRequest({
|
||||
url: "https://admin.pena.digital/strator/account",
|
||||
method: "get",
|
||||
bearer: true,
|
||||
contentType: true,
|
||||
})
|
||||
const radioboxes = ["a", "b", "c"];
|
||||
|
||||
const [selectedValue, setSelectedValue] = React.useState("a");
|
||||
|
@ -53,7 +53,7 @@ const Header: React.FC = () => {
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
makeRequest({
|
||||
url: "https://admin.pena.digital/auth/logout",
|
||||
url: "https://admin.pena.digital/auth/auth/logout",
|
||||
contentType: true,
|
||||
}).then(() => localStorage.setItem("AT", ""));
|
||||
}}
|
||||
|
@ -17,6 +17,7 @@ interface FirstRequest<T> {
|
||||
body?: T;
|
||||
useToken?: boolean;
|
||||
contentType?: boolean;
|
||||
bearer?: boolean;
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
|
||||
@ -50,13 +51,14 @@ async function makeRequest<TRequest, TResponse>({
|
||||
useToken = true,
|
||||
signal,
|
||||
contentType = false,
|
||||
bearer = false,
|
||||
HC,
|
||||
token,
|
||||
}: MakeRequest<TRequest>) {
|
||||
//В случае 401 рефреш должен попробовать вызваться 1 раз
|
||||
let counterRefresh = true;
|
||||
let headers: any = {};
|
||||
if (useToken) headers["Authorization"] = token;
|
||||
if (useToken) headers["Authorization"] = bearer ? "Bearer " + token : token;
|
||||
if (contentType) headers["Content-Type"] = "application/json";
|
||||
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user