yew_oauth2/components/
noauth.rs

1//! The [`NotAuthenticated`] component
2
3use super::missing_context;
4use crate::context::OAuth2Context;
5use yew::prelude::*;
6
7/// Properties for the [`NotAuthenticated`] component
8#[derive(Clone, Debug, PartialEq, Properties)]
9pub struct Props {
10    pub children: Children,
11}
12
13/// Yew component, rendering children when the agent is not authenticated.
14#[function_component(NotAuthenticated)]
15pub fn not_authenticated(props: &Props) -> Html {
16    let auth = use_context::<OAuth2Context>();
17
18    match auth {
19        None => missing_context(),
20        Some(OAuth2Context::NotInitialized) => html!(),
21        Some(OAuth2Context::NotAuthenticated { .. } | OAuth2Context::Failed(..)) => {
22            html!({ for props.children.iter() })
23        }
24        Some(OAuth2Context::Authenticated { .. }) => {
25            html!()
26        }
27    }
28}