Skip to content

Commit

Permalink
Update client app to pass auth redirect tests:
Browse files Browse the repository at this point in the history
* Update 'PrivateRoute' to automatically redirect to '/customer_area' if secret key is available
* Remove 'Unauthorized' route (and component) - no longer used
  • Loading branch information
ikusteu committed Jul 6, 2023
1 parent b70d7db commit dad5582
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 114 deletions.
2 changes: 0 additions & 2 deletions packages/client/src/AppContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import { getOrganization } from "@/lib/getters";

import PrivateRoute from "@/components/auth/PrivateRoute";
import Unauthorized from "@/components/auth/Unauthorized";
import LoginRoute from "@/components/auth/LoginRoute";

import AttendancePage from "@/pages/attendance";
Expand Down Expand Up @@ -87,7 +86,6 @@ const AppContent: React.FC = () => {
path={`${Routes.CustomerArea}/:secretKey`}
component={CustomerAreaPage}
/>
<Route path={Routes.Unauthorized} component={Unauthorized} exact />
<Route path={Routes.SelfRegister} component={SelfRegister} exact />
<Route path={Routes.Debug} component={DebugPage} />
</Switch>
Expand Down
14 changes: 6 additions & 8 deletions packages/client/src/components/auth/PrivateRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useSelector } from "react-redux";

import { Routes } from "@eisbuk/shared/ui";

import Unauthorized from "./Unauthorized";
import Loading from "./Loading";

import {
Expand Down Expand Up @@ -34,18 +33,17 @@ const PrivateRoute: React.FC<RouteProps> = (props) => {
case isAdmin:
return <Route {...props} />;

// Render login route if no auth loaded
// Render login route if no auth after initial load
case isAuthEmpty:
return <Redirect to={Routes.Login} />;

// If auth not empty (auth user exists), and there's no secret key (registration is not completed -> customer is not created in firestore)
// redirect to self registration form
case !isAuthEmpty && !secretKey:
return <Redirect to={Routes.SelfRegister} />;
case Boolean(secretKey):
return <Redirect to={[Routes.CustomerArea, secretKey].join("/")} />;

// Render "unauthorized"
// The auth exists - user exists in firebase auth, but there's no secret
// key - redirect to complte registration
default:
return <Unauthorized />;
return <Redirect to={Routes.SelfRegister} />;
}
};

Expand Down
18 changes: 0 additions & 18 deletions packages/client/src/components/auth/Unauthorized.stories.tsx

This file was deleted.

86 changes: 0 additions & 86 deletions packages/client/src/components/auth/Unauthorized.tsx

This file was deleted.

0 comments on commit dad5582

Please sign in to comment.