Skip to content

Commit

Permalink
set up user auth frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitj committed May 31, 2023
1 parent 5c5bc03 commit 9ce8ebb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as ReactDOM from "react-dom";
import afidsBanner from "../../public/afids_banner.png";

interface NavBarProps {
currentUser: string | null;
isLoggedIn: boolean;
}

interface NavProps {
Expand All @@ -13,7 +13,7 @@ interface NavProps {
target: string;
}

function NavBar({ currentUser }: NavBarProps) {
function NavBar({ isLoggedIn }: NavBarProps) {
// Default navigation bar
const navData: NavProps[] = [
{
Expand All @@ -36,7 +36,7 @@ function NavBar({ currentUser }: NavBarProps) {
url: "/contact.html",
target: "_self",
},
currentUser
isLoggedIn
? { name: "Logout", url: "/logout.html", target: "_self" }
: { name: "Login", url: "/login.html", target: "_self" },
];
Expand Down Expand Up @@ -67,9 +67,9 @@ function NavBar({ currentUser }: NavBarProps) {
}

// Need to pass currentUser from backend
function renderNavbar() {
function renderNavbar(isLoggedIn: boolean) {
ReactDOM.render(
React.createElement(NavBar, { currentUser: null }),
React.createElement(NavBar, { isLoggedIn: isLoggedIn }),
document.getElementById("react-navbar")
);
}
Expand Down
4 changes: 2 additions & 2 deletions afidsvalidator/static/lib/afidsvalidator-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import renderFooter from "./components/footer";
import renderNavbar from "./components/navbar";

globalThis.renderNavbar = renderNavbar();
globalThis.renderFooter = renderFooter();
globalThis.renderNavbar = renderNavbar;
globalThis.renderFooter = renderFooter;

export default {
renderNavbar,
Expand Down
3 changes: 2 additions & 1 deletion afidsvalidator/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@

{% block scripts %}
<script type="text/javascript" src={{url_for("static", filename="lib/afidsvalidator-react/dist/index.js") }}></script>
<script>var currentUser = "{{ current_user }}" </script>
<script>renderNavbar({{ "true" if current_user.is_authenticated else "false" }})</script>
<script>renderFooter()</script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4"
Expand Down

0 comments on commit 9ce8ebb

Please sign in to comment.