do stuffs
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-ts_proto v2.8.3
|
||||
// protoc-gen-ts_proto v2.10.1
|
||||
// protoc v6.33.1
|
||||
// source: items.proto
|
||||
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
import { AuthStatusRequest, AuthStatusResponse } from "../items";
|
||||
|
||||
export const getCsrfToken = (): string | null => {
|
||||
const match = document.cookie.match(/csrf_token=([^;]+)/);
|
||||
return match ? decodeURIComponent(match[1]) : null;
|
||||
};
|
||||
|
||||
export const apiFetch = async (
|
||||
url: string,
|
||||
options: RequestInit = {}
|
||||
): Promise<Response> => {
|
||||
const token = localStorage.getItem("token");
|
||||
const csrfToken = getCsrfToken();
|
||||
const headers = new Headers(options.headers);
|
||||
|
||||
if (token) {
|
||||
headers.set("Authorization", `Bearer ${token}`);
|
||||
}
|
||||
|
||||
if (csrfToken) {
|
||||
headers.set("X-CSRF-Token", csrfToken);
|
||||
}
|
||||
|
||||
const config = {
|
||||
...options,
|
||||
headers,
|
||||
|
||||
Reference in New Issue
Block a user