Browse Source

clean console

Signed-off-by: nameczz <zizhao.chen@zilliz.com>
nameczz 3 years ago
parent
commit
cc77d1fa45

+ 8 - 0
client/src/components/layout/GlobalEffect.tsx

@@ -2,12 +2,15 @@ import React, { useContext } from 'react';
 import axiosInstance from '../../http/Axios';
 import { rootContext } from '../../context/Root';
 import { CODE_STATUS } from '../../consts/Http';
+import { authContext } from '../../context/Auth';
+import { MILVUS_ADDRESS } from '../../consts/Localstorage';
 
 let axiosResInterceptor: number | null = null;
 // let timer: Record<string, ReturnType<typeof setTimeout> | number>[] = [];
 // we only take side effect here, nothing else
 const GlobalEffect = (props: { children: React.ReactNode }) => {
   const { openSnackBar } = useContext(rootContext);
+  const { setIsAuth, setAddress } = useContext(authContext);
 
   // catch axios error here
   if (axiosResInterceptor === null) {
@@ -25,6 +28,11 @@ const GlobalEffect = (props: { children: React.ReactNode }) => {
         switch (response.status) {
           case CODE_STATUS.UNAUTHORIZED:
             return Promise.reject(error);
+          case CODE_STATUS.FORBIDDEN:
+            setIsAuth(false);
+            setAddress('');
+            window.localStorage.removeItem(MILVUS_ADDRESS);
+            break;
           default:
             break;
         }

+ 1 - 0
client/src/consts/Http.ts

@@ -1,6 +1,7 @@
 export enum CODE_STATUS {
   SUCCESS = 200,
   UNAUTHORIZED = 401,
+  FORBIDDEN = 403,
 }
 
 export const START_LOADING_TIME = 350;

+ 2 - 1
client/src/context/Auth.tsx

@@ -16,7 +16,7 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
   const [address, setAddress] = useState<string>(
     window.localStorage.getItem(MILVUS_ADDRESS) || ''
   );
-  const [isAuth, setIsAuth] = useState<boolean>(false);
+  const [isAuth, setIsAuth] = useState<boolean>(address !== '');
   // const isAuth = useMemo(() => !!address, [address]);
 
   useEffect(() => {
@@ -29,6 +29,7 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
       try {
         const res = await MilvusHttp.check(milvusAddress);
         setAddress(res.connected ? milvusAddress : '');
+        res.connected && setIsAuth(true);
         if (!res.connected) {
           window.localStorage.removeItem(MILVUS_ADDRESS);
         }

+ 0 - 2
client/src/http/Collection.ts

@@ -31,8 +31,6 @@ export class CollectionHttp extends BaseModel implements CollectionView {
   static COLLECTIONS_INDEX_STATUS_URL = '/collections/indexes/status';
   static COLLECTIONS_STATISTICS_URL = '/collections/statistics';
 
-  static CHECK_URL = '/milvus/check';
-
   constructor(props: CollectionView) {
     super(props);
     Object.assign(this, props);