Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Only log out if receiving 401 from our own backend
天舟d0b9080257a3
diff --git a/frontend/.env.dev b/frontend/.env.devindex 083c815f94..d7fba3f837 100644--- a/frontend/.env.dev+++ b/frontend/.env.dev@@ -1 +1,2 @@-NODE_ENV=development\ No newline at end of file+NODE_ENV=development+VITE_BACKEND=http://localhost:8080\ No newline at end of filediff --git a/frontend/src/main.ts b/frontend/src/main.tsindex 8e4492debc..198635662e 100644--- a/frontend/src/main.ts+++ b/frontend/src/main.ts@@ -37,6 +37,7 @@ import highlight from "./directives/highlight";import {isDev,isRelease,+ backendURL,humanizeTs,sizeToFit,urlfy,@@ -55,6 +56,7 @@ registerStoreWithRoleUtil(store);console.debug("dev:", isDev());console.debug("release:", isRelease());+console.debug("backend:", backendURL());axios.defaults.timeout = 10000;axios.interceptors.request.use((request) => {@@ -83,9 +85,14 @@ axios.interceptors.response.use(},(error) => {if (error.response) {- // When server returns 401, it means the current login user's token becomes invalid.- // Thus we force a logout.- if (error.response.status == 401) {+ // When receiving 401 and is returned by our server, it means the current+ // login user's token becomes invalid. Thus we force a logout.+ // We could receive 401 when calling external service such as VCS provider,+ // in such case, we shouldn't logout.+ if (+ error.response.status == 401 &&+ error.response.request.responseURL.startsWith(backendURL())+ ) {store.dispatch("auth/logout").then(() => {router.push({ name: "auth.signin" });});diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.tsindex 66c22759ba..6772b668f3 100644--- a/frontend/src/utils/util.ts+++ b/frontend/src/utils/util.ts@@ -8,6 +8,16 @@ export function isRelease(): boolean {return import.meta.env.PROD;}+// Use VITE_BACKEND as the backendURL if specified. Otherwise, just use the current host+// For dev environment, we usually set VITE_BACKEND to point to different backend.+// For production environment, we won't set VITE_BACKEND because we bundle frontend/backend as a monolithic.+export function backendURL(): string {+ if (import.meta.env.VITE_BACKEND) {+ return import.meta.env.VITE_BACKEND as string;+ }+ return window.location.origin;+}+export function humanizeTs(ts: number): string {const time = moment.utc(ts * 1000);if (moment().year() == time.year()) {