mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-20 06:10:43 +00:00
QQQ-27: checkpoint commit of initial version of Auth0 integration
This commit is contained in:
28
src/qqq/auth0/code-snippet.tsx
Normal file
28
src/qqq/auth0/code-snippet.tsx
Normal file
@ -0,0 +1,28 @@
|
||||
import React from "react";
|
||||
|
||||
interface CodeSnippetProps
|
||||
{
|
||||
code: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line react/function-component-definition
|
||||
function CodeSnippet({title, code}: CodeSnippetProps): JSX.Element
|
||||
{
|
||||
return (
|
||||
<div className="code-snippet">
|
||||
<span className="code-snippet__title">{title}</span>
|
||||
<div className="code-snippet__container">
|
||||
<div className="code-snippet__wrapper">
|
||||
<pre className="code-snippet__body">{code}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
CodeSnippet.defaultProps = {
|
||||
title: undefined,
|
||||
};
|
||||
|
||||
export default CodeSnippet;
|
14
src/qqq/auth0/loader.tsx
Normal file
14
src/qqq/auth0/loader.tsx
Normal file
@ -0,0 +1,14 @@
|
||||
import React from "react";
|
||||
|
||||
function Loader() : JSX.Element
|
||||
{
|
||||
const loadingImg = "https://cdn.auth0.com/blog/hello-auth0/loader.svg";
|
||||
|
||||
return (
|
||||
<div className="loader">
|
||||
<img style={{height: "25px"}} src={loadingImg} alt="Loading..." />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Loader;
|
31
src/qqq/auth0/profile.tsx
Normal file
31
src/qqq/auth0/profile.tsx
Normal file
@ -0,0 +1,31 @@
|
||||
import {useAuth0} from "@auth0/auth0-react";
|
||||
import React from "react";
|
||||
import CodeSnippet from "./code-snippet";
|
||||
|
||||
export function Profile()
|
||||
{
|
||||
const {user} = useAuth0();
|
||||
|
||||
if (!user)
|
||||
{
|
||||
console.log("no user");
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="content-layout">
|
||||
<div className="content__body">
|
||||
<div className="profile-grid">
|
||||
<div className="profile__details">
|
||||
<CodeSnippet
|
||||
title="Decoded ID Token"
|
||||
code={JSON.stringify(user, null, 2)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Profile;
|
16
src/qqq/auth0/protected-route.tsx
Normal file
16
src/qqq/auth0/protected-route.tsx
Normal file
@ -0,0 +1,16 @@
|
||||
import {withAuthenticationRequired} from "@auth0/auth0-react";
|
||||
import React from "react";
|
||||
import Loader from "./loader";
|
||||
|
||||
// @ts-ignore
|
||||
function ProtectedRoute({component}) : JSX.Element
|
||||
{
|
||||
const Component = withAuthenticationRequired(component, {
|
||||
// eslint-disable-next-line react/no-unstable-nested-components
|
||||
onRedirecting: () => <Loader />,
|
||||
});
|
||||
|
||||
return <Component />;
|
||||
}
|
||||
|
||||
export default ProtectedRoute;
|
Reference in New Issue
Block a user