diff --git a/client/src/App.vue b/client/src/App.vue index e23dff6..594b84c 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -3,22 +3,62 @@ import IDashboard from '~icons/ri/dashboard-2-line'; import IRule from '~icons/material-symbols/rule-folder-outline-sharp'; import IAddress from '~icons/eos-icons/ip'; - +import { authenticate, checkAuthentication, setup } from "./api"; enum NavState { Open, Reduced, Collapsed }; const NavStateCount = 3; let navState = $ref(NavState.Open); -let loggedOut = $ref(false); - const navRoutes = { "/": { icon: IDashboard, caption: "Dashboard" }, "/rules": { icon: IRule, caption: "Rules" }, "/addresses": { icon: IAddress, caption: "Addresses" }, }; + +enum AuthState { Unauthenticated, MfaRequired, Authenticated }; +let authState = $ref(AuthState.Unauthenticated); +let loginDisabled = $ref(true); + +let username = $ref(""); +let password = $ref(""); + + +async function tryLogin() { + loginDisabled = true; + const res = await authenticate(username, password); + password = ""; + loginDisabled = false; + if (res.error != null) { + console.info("authentication error"); + } else { + // TODO Check for MFA here + authState = 1; + } +} + +async function tryLogout() { + authState = 0; +} + +function deAuthenticatedCallback() { + console.info("Unauthenticated"); + authState = 0; +} + +onMounted(async() => { + setup(deAuthenticatedCallback); + let res = await checkAuthentication(); + authState = res.auth; + loginDisabled = false; + if (authState > 0) { + console.info("Already Authenticated ", authState); + } + else console.info("Check Authentication error",res.error); +}); +