Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-town committed May 2, 2024
1 parent 5a35787 commit 8f7da3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions dashboard/src/main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import api from "shared/api";
import { Context } from "shared/Context";
import { PorterUrls, type PorterUrl } from "shared/routing";

import { AuthnContext } from "../shared/auth/AuthnContext";
import { useAuthn } from "../shared/auth/AuthnContext";
import CurrentError from "./CurrentError";
import Home from "./home/Home";

Expand All @@ -22,7 +22,7 @@ const Main: React.FC<PropsType> = () => {
currentProject,
currentCluster,
} = useContext(Context);
const { handleLogOut } = useContext(AuthnContext);
const { handleLogOut } = useAuthn();
const [version, setVersion] = useState("");

useEffect(() => {
Expand All @@ -48,7 +48,7 @@ const Main: React.FC<PropsType> = () => {
}, []);

const renderMain = (): JSX.Element => {
if (!version || !currentProject || !currentCluster) {
if (!version) {
return <Loading />;
}

Expand Down
13 changes: 8 additions & 5 deletions dashboard/src/shared/auth/AuthnContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ type AuthnState = {
handleLogOut: () => void;
};

const NilAuthnState = {
userId: -1,
handleLogOut: () => {},
};
export const AuthnContext = React.createContext<AuthnState | null>(null);

export const AuthnContext = React.createContext<AuthnState>(NilAuthnState);
export const useAuthn = (): AuthnState => {
const context = useContext(AuthnContext);
if (context == null) {
throw new Error("useAuthn must be used within an AuthnContext");
}
return context;
};

const AuthnProvider = ({
children,
Expand Down

0 comments on commit 8f7da3a

Please sign in to comment.