Kaynağa Gözat

add current error to unauthed routes

dgtown 2 yıl önce
ebeveyn
işleme
53e016d688

+ 2 - 1
dashboard/src/main/MainWrapper.tsx

@@ -7,6 +7,7 @@ import MainWrapperErrorBoundary from "shared/error_handling/MainWrapperErrorBoun
 import AuthnProvider from "../shared/auth/AuthnContext";
 import { ContextProvider } from "../shared/Context";
 import Main from "./Main";
+import CurrentError from "./CurrentError";
 
 type PropsType = RouteComponentProps & {};
 
@@ -24,4 +25,4 @@ const MainWrapper: React.FC<PropsType> = ({ history, location }) => {
   );
 };
 
-export default withRouter(MainWrapper);
+export default withRouter(MainWrapper);

+ 65 - 54
dashboard/src/shared/auth/AuthnContext.tsx

@@ -11,6 +11,7 @@ import ResetPasswordFinalize from "../../main/auth/ResetPasswordFinalize";
 import ResetPasswordInit from "../../main/auth/ResetPasswordInit";
 import SetInfo from "../../main/auth/SetInfo";
 import VerifyEmail from "../../main/auth/VerifyEmail";
+import CurrentError from "../../main/CurrentError";
 
 type AuthnState = {
   userId: number;
@@ -32,7 +33,8 @@ const AuthnProvider = ({
 }: {
   children: JSX.Element;
 }): JSX.Element => {
-  const { setUser, clearContext, setCurrentError } = useContext(Context);
+  const { setUser, clearContext, setCurrentError, currentError } =
+    useContext(Context);
   const [isLoggedIn, setIsLoggedIn] = useState(false);
   const [isEmailVerified, setIsEmailVerified] = useState(false);
   const [isLoading, setIsLoading] = useState(true);
@@ -103,71 +105,80 @@ const AuthnProvider = ({
   // return unauthenticated routes
   if (!isLoggedIn) {
     return (
-      <Switch>
-        <Route
-          path="/login"
-          render={() => {
-            return <Login authenticate={authenticate} />;
-          }}
-        />
-        <Route
-          path="/register"
-          render={() => {
-            return <Register authenticate={authenticate} />;
-          }}
-        />
-        <Route
-          path="/password/reset/finalize"
-          render={() => {
-            return <ResetPasswordFinalize />;
-          }}
-        />
-        <Route
-          path="/password/reset"
-          render={() => {
-            return <ResetPasswordInit />;
-          }}
-        />
-        <Route
-          path="*"
-          render={() => {
-            return <Redirect to="/login" />;
-          }}
-        />
-      </Switch>
+      <>
+        <Switch>
+          <Route
+            path="/login"
+            render={() => {
+              return <Login authenticate={authenticate} />;
+            }}
+          />
+          <Route
+            path="/register"
+            render={() => {
+              return <Register authenticate={authenticate} />;
+            }}
+          />
+          <Route
+            path="/password/reset/finalize"
+            render={() => {
+              return <ResetPasswordFinalize />;
+            }}
+          />
+          <Route
+            path="/password/reset"
+            render={() => {
+              return <ResetPasswordInit />;
+            }}
+          />
+          <Route
+            path="*"
+            render={() => {
+              return <Redirect to="/login" />;
+            }}
+          />
+        </Switch>
+        <CurrentError currentError={currentError} />
+      </>
     );
   }
 
   // if logged in but not verified, block until email verification
   if (!local && !isEmailVerified) {
     return (
-      <Switch>
-        <Route
-          path="/"
-          render={() => {
-            return <VerifyEmail handleLogOut={handleLogOut} />;
-          }}
-        />
-      </Switch>
+      <>
+        <Switch>
+          <Route
+            path="/"
+            render={() => {
+              return <VerifyEmail handleLogOut={handleLogOut} />;
+            }}
+          />
+        </Switch>
+        <CurrentError currentError={currentError} />
+      </>
     );
   }
 
   // Handle case where new user signs up via OAuth and has not set name and company
   if (!hasInfo && userId > 9312) {
     return (
-      <Switch>
-        <Route
-          path="/"
-          render={() => {
-            return (
-              <SetInfo
-                handleLogOut={handleLogOut}
-                authenticate={authenticate}
-              />
-            );
-          }}
-        />
-      </Switch>
+      <>
+        <Switch>
+          <Route
+            path="/"
+            render={() => {
+              return (
+                <SetInfo
+                  handleLogOut={handleLogOut}
+                  authenticate={authenticate}
+                />
+              );
+            }}
+          />
+        </Switch>
+        <CurrentError currentError={currentError} />
+      </>
     );
   }