chore: Use httpOnly authentication cookie (#5552)
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import retry from "fetch-retry";
|
||||
import invariant from "invariant";
|
||||
import { trim } from "lodash";
|
||||
import queryString from "query-string";
|
||||
import EDITOR_VERSION from "@shared/editor/version";
|
||||
import stores from "~/stores";
|
||||
import isCloudHosted from "~/utils/isCloudHosted";
|
||||
import Logger from "./Logger";
|
||||
import download from "./download";
|
||||
import {
|
||||
@@ -95,14 +93,8 @@ class ApiClient {
|
||||
}
|
||||
|
||||
const headers = new Headers(headerOptions);
|
||||
|
||||
if (stores.auth.authenticated) {
|
||||
invariant(stores.auth.token, "JWT token not set properly");
|
||||
headers.set("Authorization", `Bearer ${stores.auth.token}`);
|
||||
}
|
||||
|
||||
let response;
|
||||
const timeStart = window.performance.now();
|
||||
let response;
|
||||
|
||||
try {
|
||||
response = await fetchWithRetry(urlToFetch, {
|
||||
@@ -110,15 +102,7 @@ class ApiClient {
|
||||
body,
|
||||
headers,
|
||||
redirect: "follow",
|
||||
// For the hosted deployment we omit cookies on API requests as they are
|
||||
// not needed for authentication this offers a performance increase.
|
||||
// For self-hosted we include them to support a wide variety of
|
||||
// authenticated proxies, e.g. Pomerium, Cloudflare Access etc.
|
||||
credentials: options.credentials
|
||||
? options.credentials
|
||||
: isCloudHosted
|
||||
? "omit"
|
||||
: "same-origin",
|
||||
credentials: "same-origin",
|
||||
cache: "no-cache",
|
||||
});
|
||||
} catch (err) {
|
||||
@@ -147,7 +131,8 @@ class ApiClient {
|
||||
|
||||
// Handle 401, log out user
|
||||
if (response.status === 401) {
|
||||
await stores.auth.logout();
|
||||
const tokenIsExpired = true;
|
||||
await stores.auth.logout(false, tokenIsExpired);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user