| 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::context::{claimed, identity, orgs, server_error, users}; |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | #[page("/")] |
| 26 | async fn home(cx: &Cx) -> Result { |
| 27 | if !claimed(cx).await? { |
| 28 | return Err(redirect("/auth/setup").into()); |
| 29 | } |
| 30 | |
| 31 | if let Some(identity) = identity(cx).await? { |
| 32 | return Err(redirect(&format!("/{}", identity.handle)).into()); |
| 33 | } |
| 34 | |
| 35 | if let Some(owner) = sole_owner_handle(&users(cx), &orgs(cx)) |
| 36 | .await |
| 37 | .map_err(server_error)? |
| 38 | { |
| 39 | return Err(redirect(&format!("/{owner}")).into()); |
| 40 | } |
| 41 | |
| 42 | view! { |
| 43 | <h1>"steid"</h1> |
| 44 | <p><a href="/auth/login">"Sign in"</a></p> |
| 45 | } |
| 46 | } |