steid

@jamesgill /

14223e7feat: claim, sign in, and sign out through the browser1mo
1use topcoat::{
2 Result,
3 context::Cx,
4 router::{error::redirect, page},
5 view::view,
6};
7
40ab5c7feat: /api/me and a shared identity read model1mo
8use super::context::{claimed, identity};
14223e7feat: claim, sign in, and sign out through the browser1mo
9
10/// The home page.
11///
12/// A placeholder until Milestone 2 makes `/{owner}` the real one, but enough to prove
13/// the identity flow end to end.
40ab5c7feat: /api/me and a shared identity read model1mo
14///
15/// Reads through the same `describe_identity` use case that `/api/me` uses — which is
16/// the point of keeping it in the application layer rather than querying here.
14223e7feat: claim, sign in, and sign out through the browser1mo
17#[page("/")]
18async fn home(cx: &Cx) -> Result {
19 if !claimed(cx).await? {
20 return Err(redirect("/setup").into());
21 }
22
23 view! {
24 <h1>"steid"</h1>
40ab5c7feat: /api/me and a shared identity read model1mo
25 (match identity(cx).await? {
26 Some(identity) => view! {
27 <p>"Signed in as " <strong>(identity.handle.as_str())</strong></p>
28 <p>(identity.email.as_str())</p>
14223e7feat: claim, sign in, and sign out through the browser1mo
29 <form method="post" action="/logout">
30 <button type="submit">"Sign out"</button>
31 </form>
32 },
40ab5c7feat: /api/me and a shared identity read model1mo
33 None => view! {
14223e7feat: claim, sign in, and sign out through the browser1mo
34 <p>"Not signed in."</p>
35 <p><a href="/login">"Sign in"</a></p>
36 },
37 }?)
38 }
39}