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