Redirect to login page if not currently logged in

This commit is contained in:
Quentin Boyer 2023-05-20 12:27:33 +02:00
parent 54f1c3233f
commit 062a749d59

View file

@ -6,6 +6,8 @@ use yew_router::prelude::*;
enum Route {
#[at("/")]
Index,
#[at("/login")]
Login,
#[at("/404")]
#[not_found]
NotFound,
@ -25,7 +27,10 @@ fn App() -> Html {
fn switch(route: Route) -> Html {
match route {
Route::Index => html! {
"Index"
<Index />
},
Route::Login => html! {
"Login"
},
Route::NotFound => html! {
"Page not found"
@ -33,6 +38,20 @@ fn switch(route: Route) -> Html {
}
}
#[function_component]
fn Index() -> Html {
let token = use_state(|| None::<String>);
match &*token {
Some(_) => html! {
"Index"
},
None => html! {
<Redirect<Route> to={Route::Login} />
},
}
}
fn main() {
console_log::init_with_level(Level::Debug).unwrap();