| 1 | use topcoat::{ |
| 2 | Result, |
| 3 | context::Cx, |
| 4 | router::{error::redirect, page}, |
| 5 | view::view, |
| 6 | }; |
| 7 | |
| 8 | use crate::application::sole_owner_handle; |
| 9 | |
| 10 | use super::{ |
| 11 | context::{claimed, identity, orgs, server_error, users}, |
| 12 | layout::narrow, |
| 13 | }; |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | #[page("/")] |
| 29 | async fn home(cx: &Cx) -> Result { |
| 30 | if !claimed(cx).await? { |
| 31 | return Err(redirect("/auth/setup").into()); |
| 32 | } |
| 33 | |
| 34 | if let Some(identity) = identity(cx).await? { |
| 35 | return Err(redirect(&format!("/{}", identity.handle)).into()); |
| 36 | } |
| 37 | |
| 38 | if let Some(owner) = sole_owner_handle(&users(cx), &orgs(cx)) |
| 39 | .await |
| 40 | .map_err(server_error)? |
| 41 | { |
| 42 | return Err(redirect(&format!("/{owner}")).into()); |
| 43 | } |
| 44 | |
| 45 | view! { |
| 46 | narrow( |
| 47 | <h1>"steid"</h1> |
| 48 | <p><a href="/auth/login">"Sign in"</a></p> |
| 49 | ) |
| 50 | } |
| 51 | } |