yew_oauth2/components/
authenticated.rs

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