-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix issue where useEffect running twice as causing exception and breaking prod auth flow. Add a Public Route component that prevents logged in users from going to log in page * Add ProtectedRoute component. Fix log-out component * Fix effect logic * Add sentry logging when initAuth method fails. Add comments and improve logic in auth interstitial page
- Loading branch information
1 parent
c3f2f07
commit e0d09f8
Showing
4 changed files
with
90 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from "react"; | ||
import { | ||
Redirect, | ||
Route, | ||
RouteComponentProps, | ||
RouteProps, | ||
} from "react-router-dom"; | ||
|
||
interface PublicRouteProps extends RouteProps { | ||
// The type here is copied from the react-router component typing in react-router/index.d.ts | ||
component: | ||
| React.ComponentType<RouteComponentProps<any>> | ||
| React.ComponentType<any>; | ||
isAuthenticated: boolean; | ||
redirectTo?: string; | ||
} | ||
|
||
export const PublicRoute = ({ | ||
component: Component, | ||
isAuthenticated, | ||
redirectTo = "/navigator-dashboard", | ||
...rest | ||
}: PublicRouteProps) => { | ||
return ( | ||
<Route | ||
{...rest} | ||
render={(props) => | ||
!isAuthenticated ? ( | ||
<Component {...props} /> | ||
) : ( | ||
<Redirect to={{ pathname: redirectTo }} /> | ||
) | ||
} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./ProtectedRoute"; | ||
export * from "./PublicRoute"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters