//! This is the top level router of the web ui for kanidm. It decides based on the incoming
//! request, where to direct this too, and if the requirements for that request have been
//! met before rendering. For example, if you land here with an oauth request, but you are
//! not authenticated, this will determine that and send you to authentication first, then
//! will allow you to proceed with the oauth flow.
use gloo::console;
use serde::{Deserialize, Serialize};
use wasm_bindgen::UnwrapThrowExt;
use yew::functional::*;
use yew::prelude::*;
use yew_router::prelude::*;
use crate::credential::reset::CredentialResetApp;
use crate::login::{LoginApp, LoginWorkflow};
use crate::oauth2::Oauth2App;
use crate::views::{ViewRoute, ViewsApp};
// router to decide on state.
#[derive(Routable, PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
pub enum Route {
#[at("/ui")]
Landing,
#[at("/ui/login")]
Login,
#[at("/ui/reauth")]
Reauth,
#[at("/ui/oauth2")]
Oauth2,
#[at("/ui/reset")]
CredentialReset,
#[not_found]
#[at("/ui/404")]
NotFound,
#[at("/ui/*")]
Views,
}
#[function_component(Landing)]
fn landing() -> Html {
#[cfg(debug_assertions)]
console::debug!("manager::landing");
// Do this to allow use_navigator to work because lol.
yew_router::hooks::use_navigator()
.expect_throw("Unable to access history")
.push(&ViewRoute::Apps);
html! { }
}
// Needed for yew to pass by value
#[allow(clippy::needless_pass_by_value)]
fn switch(route: Route) -> Html {
#[cfg(debug_assertions)]
console::debug!(format!("manager::switch -> {:?}", route).as_str());
match route {
#[allow(clippy::let_unit_value)]
Route::Landing => html! { },
#[allow(clippy::let_unit_value)]
Route::Login => html! { },
#[allow(clippy::let_unit_value)]
Route::Reauth => html! { },
#[allow(clippy::let_unit_value)]
Route::Oauth2 => html! { },
#[allow(clippy::let_unit_value)]
Route::Views => html! { },
#[allow(clippy::let_unit_value)]
Route::CredentialReset => html! { },
Route::NotFound => {
add_body_form_classes!();
html! {
<>
// TODO: replace this with a call to domain info