Sfoglia il codice sorgente

retrieve capabilities for casing login

Justin Rhee 3 anni fa
parent
commit
f7967e923a
2 ha cambiato i file con 24 aggiunte e 2 eliminazioni
  1. 14 2
      dashboard/src/main/Main.tsx
  2. 10 0
      dashboard/src/main/auth/Register.tsx

+ 14 - 2
dashboard/src/main/Main.tsx

@@ -24,6 +24,7 @@ type StateType = {
   initialized: boolean;
   local: boolean;
   userId: number;
+  version: string;
 };
 
 export default class Main extends Component<PropsType, StateType> {
@@ -35,9 +36,20 @@ export default class Main extends Component<PropsType, StateType> {
     initialized: localStorage.getItem("init") === "true",
     local: false,
     userId: null as number,
+    version: null as string,
   };
 
   componentDidMount() {
+
+    // Get capabilities to case on user info requirements
+    api.getMetadata("", {}, {})
+      .then((res) => {
+        this.setState({
+          version: res.data?.version,
+        })
+      })
+      .catch((err) => console.log(err));
+
     let { setUser, setCurrentError } = this.context;
     let urlParams = new URLSearchParams(window.location.search);
     let error = urlParams.get("error");
@@ -111,7 +123,7 @@ export default class Main extends Component<PropsType, StateType> {
   };
 
   renderMain = () => {
-    if (this.state.loading) {
+    if (this.state.loading || !this.state.version) {
       return <Loading />;
     }
 
@@ -135,7 +147,7 @@ export default class Main extends Component<PropsType, StateType> {
 
     // Handle case where new user signs up via OAuth and has not set name and company
     if (
-      this.context.capabilities.version === "production" &&
+      this.state.version === "production" &&
       !this.state.hasInfo && 
       this.state.userId > 9312 &&
       this.state.isLoggedIn

+ 10 - 0
dashboard/src/main/auth/Register.tsx

@@ -119,6 +119,16 @@ const Register: React.FC<Props> = ({
   }, [email, password, firstName, lastName]);
 
   useEffect(() => {
+
+    // Get capabilities to case on login methods
+    api.getMetadata("", {}, {})
+      .then((res) => {
+        setHasBasic(res.data?.basic_login);
+        setHasGithub(res.data?.github_login);
+        setHasGoogle(res.data?.google_login);
+      })
+      .catch((err) => console.log(err));
+
     window.addEventListener('resize', handleResize);
     return () => window.removeEventListener('resize', handleResize);
   }, []);