Created
December 16, 2021 21:09
-
-
Save rschwabco/cdf7c2541b50328bd9efae0e449e2180 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React, { useEffect } from "react"; | |
import { useAuth } from "oidc-react"; | |
function App() { | |
const auth = useAuth(); | |
const isAuthenticated = auth.userData?.id_token ? true : false; | |
//If the user logs out, redirect them to the login page | |
useEffect(() => { | |
if (!auth.isLoading && !isAuthenticated) { | |
auth.signIn(); | |
} | |
}); | |
return ( | |
<div className="container"> | |
<div className="header"> | |
<div className="logo-container"> | |
<div className="logo"></div> | |
<div className="brand-name"></div> | |
</div> | |
</div> | |
<div className="user-controls"> | |
{isAuthenticated && ( | |
<> | |
<div className="user-info">{auth.userData?.profile?.email}</div> | |
<div className="seperator"></div> | |
<div className="auth-button"> | |
<div onClick={() => auth.signOut("/")}>Log Out</div> | |
</div> | |
</> | |
)} | |
{!isAuthenticated && ( | |
<div className="auth-button"> | |
<div onClick={() => auth.signIn("/")}>Login</div> | |
</div> | |
)} | |
</div> | |
<div className="main"> | |
{isAuthenticated && ( | |
<> | |
<div className="top-main"> | |
<div className="welcome-message"> | |
Welcome {auth.userData?.profile?.email}! | |
</div> | |
</div> | |
</> | |
)} | |
</div> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment