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:
19
src/components/SSOForm/SSOForm.test.js
Normal file
19
src/components/SSOForm/SSOForm.test.js
Normal file
@@ -0,0 +1,19 @@
|
||||
jest.mock("../Contexts/UserContext");
|
||||
|
||||
import React from "react";
|
||||
import { BrowserRouter } from "react-router-dom";
|
||||
import { render, cleanup } from "@testing-library/react";
|
||||
import SSOForm from "./index";
|
||||
|
||||
describe("Sign In Form", () => {
|
||||
it("Should render", () => {
|
||||
const { container } = render(
|
||||
<BrowserRouter>
|
||||
<SSOForm />
|
||||
</BrowserRouter>
|
||||
);
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
cleanup();
|
||||
});
|
||||
});
|
||||
40
src/components/SSOForm/__snapshots__/SSOForm.test.js.snap
Normal file
40
src/components/SSOForm/__snapshots__/SSOForm.test.js.snap
Normal file
@@ -0,0 +1,40 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Sign In Form Should render 1`] = `
|
||||
<div>
|
||||
<main
|
||||
class="MuiContainer-root MuiContainer-maxWidthXs"
|
||||
>
|
||||
<div
|
||||
class="makeStyles-paper-1"
|
||||
>
|
||||
<h1
|
||||
class="MuiTypography-root MuiTypography-h5"
|
||||
>
|
||||
Fisker OTA Portal
|
||||
</h1>
|
||||
<form
|
||||
action="{onSubmit}"
|
||||
class="makeStyles-form-3"
|
||||
novalidate=""
|
||||
>
|
||||
<a
|
||||
aria-disabled="false"
|
||||
class="MuiButtonBase-root MuiButton-root MuiButton-contained makeStyles-submit-4 MuiButton-containedPrimary MuiButton-fullWidth"
|
||||
href="https://cognito.com/authorize?redirect=https://example.com/callback"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
class="MuiButton-label"
|
||||
>
|
||||
Sign In
|
||||
</span>
|
||||
<span
|
||||
class="MuiTouchRipple-root"
|
||||
/>
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
`;
|
||||
45
src/components/SSOForm/index.jsx
Normal file
45
src/components/SSOForm/index.jsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import React, { useEffect } from "react";
|
||||
import { Button, Container, CssBaseline, Typography } from "@material-ui/core";
|
||||
import { useUserContext } from "../Contexts/UserContext";
|
||||
import useStyles from "../useStyles";
|
||||
|
||||
const getCode = (search) => {
|
||||
if (!search) return null;
|
||||
const s = new URLSearchParams(search);
|
||||
return s.get("code");
|
||||
};
|
||||
|
||||
export default function SignInForm() {
|
||||
const classes = useStyles();
|
||||
const { getAuthorizeURL, signIn } = useUserContext();
|
||||
|
||||
useEffect(() => {
|
||||
const code = getCode(document.location.search);
|
||||
if (!code) return;
|
||||
signIn(code);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Container component="main" maxWidth="xs">
|
||||
<CssBaseline />
|
||||
<div className={classes.paper}>
|
||||
<Typography component="h1" variant="h5">
|
||||
Fisker OTA Portal
|
||||
</Typography>
|
||||
<form className={classes.form} noValidate action="{onSubmit}">
|
||||
<Button
|
||||
type="submit"
|
||||
fullWidth
|
||||
variant="contained"
|
||||
color="primary"
|
||||
className={classes.submit}
|
||||
href={getAuthorizeURL()}
|
||||
>
|
||||
Sign In
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user