Commit 98cd9ad4 authored by David Haynes's avatar David Haynes 🙆

Add registration check to authed pages

- ie. you can't perform any authenticated operations until you have registered
parent 5de2a7b9
import React from "react";
import { Container } from "reactstrap";
import useAuthCheck from "../../Utils/useAuthCheck";
import useRegistrationCheck from "../../Utils/useRegistrationCheck";
const AuthedPageTemplate = props => {
const { isLoggedIn, loaded } = useAuthCheck();
const { isLoggedIn, authLoaded } = useAuthCheck();
const { isRegistered, registeredLoaded } = useRegistrationCheck();
return (
<div>
{loaded ? (
{authLoaded && registeredLoaded ? (
<div>
{isLoggedIn ? (
<Container>{props.children}</Container>
<div>
{isRegistered ? (
<Container>{props.children}</Container>
) : (
<div>You are logged in but not registered!</div>
)}
</div>
) : (
<h1>You're not authed!</h1>
)}
</div>
) : (
<div />
<div>shits fucked my man</div>
)}
</div>
);
......
......@@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react";
const useAuthCheck = () => {
const [isLoggedIn, setIsLoggedIn] = useState(null);
const [loaded, setLoaded] = useState(false);
const [authLoaded, setAuthLoaded] = useState(false);
const getAuthStatus = async () => {
let response = await fetch("/auth/status/", {
......@@ -12,14 +12,14 @@ const useAuthCheck = () => {
});
let data = await response.json();
setIsLoggedIn(data.is_authenticated);
setLoaded(true);
setAuthLoaded(true);
};
useEffect(() => {
getAuthStatus();
}, []);
return { isLoggedIn, loaded };
return { isLoggedIn, authLoaded };
};
export default useAuthCheck;
import React, { useState, useEffect } from "react";
/**
* Hook to get whether or not the currently logged in user is registered.
*/
const useRegistrationCheck = () => {
const [isRegistered, setIsRegistered] = useState(null);
const [registeredLoaded, setRegisteredLoaded] = useState(false);
const getRegistrationStatus = async () => {
let response = await fetch("/auth/status/", {
headers: {
"Content-Type": "application/json"
}
});
let data = await response.json();
setIsRegistered(data.is_registered);
setRegisteredLoaded(true);
};
useEffect(() => {
getRegistrationStatus();
}, []);
return { isRegistered, registeredLoaded };
};
export default useRegistrationCheck;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment