Use compute auth service and fix static code analyzer warnings (#15)

* Clean up formatting

* Use new compute_auth service
Implment SSO
Implement token refresh
Clean up unit tests

* Fix unit tests

* Fix auth test
Fix warnings

* Update default settings for compute_auth
This commit is contained in:
John Wu
2021-03-04 14:30:56 -08:00
committed by GitHub
parent e1f0006d5e
commit 39e779dc1d
34 changed files with 703 additions and 1462 deletions

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import React from "react";
import { Redirect, Route } from "react-router-dom";
export const TYPES = {
PUBLIC: 0,
@@ -9,10 +9,9 @@ export const TYPES = {
export const AuthRoute = ({ token, type, ...others }) => {
if (!token && type === TYPES.PROTECTED) {
return <Redirect to="/" />;
}
else if (token && type === TYPES.GUEST) {
return <Redirect to="/" />;
} else if (token && type === TYPES.GUEST) {
return <Redirect to="/home" />;
}
return <Route render {...others} />;
}
};

View File

@@ -1,13 +1,13 @@
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import { useUserContext } from '../Contexts/UserContext';
import React from "react";
import { Redirect, Route } from "react-router-dom";
import { useUserContext } from "../Contexts/UserContext";
export const ProtectedRoute = ({ render, ...others }) => {
const context = useUserContext();
const { token, setError } = context;
if (!token) {
setError('Please sign in to access');
return <Redirect to="/" />;
}
return <Route render {...others} />;
}
const context = useUserContext();
const { token, setError } = context;
if (!token) {
setError("Please sign in to access");
return <Redirect to="/" />;
}
return <Route render {...others} />;
};

View File

@@ -1,34 +1,39 @@
import React, { Suspense } from 'react';
import {
BrowserRouter,
Switch,
} from 'react-router-dom';
import React, { Suspense } from "react";
import { BrowserRouter, Switch } from "react-router-dom";
import { AuthRoute, TYPES } from '../Routes/AuthRoute'
import { MessageBar } from '../MessageBar';
import { useUserContext } from '../Contexts/UserContext';
import { AuthRoute, TYPES } from "../Routes/AuthRoute";
import { MessageBar } from "../MessageBar";
import { useUserContext } from "../Contexts/UserContext";
const SignInForm = React.lazy(() => import('../SignInForm'));
const SignUpForm = React.lazy(() => import('../SignUpForm'));
const FileUploadForm = React.lazy(() => import('../FileUploadForm'));
const PageNotFound = React.lazy(() => import('../404'));
const SSOForm = React.lazy(() => import("../SSOForm"));
const FileUploadForm = React.lazy(() => import("../FileUploadForm"));
const PageNotFound = React.lazy(() => import("../404"));
const SiteRoutes = () => {
const { token } = useUserContext();
return (
<Suspense fallback={"Loading..."}>
<Suspense fallback={"Loading..."}>
<MessageBar />
<BrowserRouter>
<Switch>
<AuthRoute path="/" exact render={() => <SignInForm />} type={TYPES.GUEST} token={token} />
<AuthRoute path="/signup" exact render={() => <SignUpForm />} type={TYPES.GUEST} token={token} />
<AuthRoute path="/home" render={() => <FileUploadForm />} type={TYPES.PROTECTED} token={token} />
<AuthRoute
path="/"
exact
render={() => <SSOForm />}
type={TYPES.GUEST}
token={token}
/>
<AuthRoute
path="/home"
render={() => <FileUploadForm />}
type={TYPES.PROTECTED}
token={token}
/>
<PageNotFound />
</Switch>
</Switch>
</BrowserRouter>
</Suspense>
);
};
export default SiteRoutes;
export default SiteRoutes;