yew_oauth2/components/redirect/
location.rs

1//! Redirect by setting the browser's location directly.
2
3use super::{Redirect, Redirector, RedirectorProperties};
4use gloo_utils::window;
5use yew::prelude::*;
6
7/// A redirector using the browser's location.
8pub struct LocationRedirector;
9
10impl Redirector for LocationRedirector {
11    type Properties = LocationProperties;
12
13    fn new<COMP: Component>(_: &Context<COMP>) -> Self {
14        Self {}
15    }
16
17    fn logout(&self, props: &Self::Properties) {
18        log::debug!("Navigate due to logout: {}", props.logout_href);
19        window().location().set_href(&props.logout_href).ok();
20    }
21}
22
23#[derive(Clone, Debug, PartialEq, Properties)]
24pub struct LocationProperties {
25    /// The content to show when being logged in.
26    #[prop_or_default]
27    pub children: Html,
28
29    /// The logout URL to redirect to
30    pub logout_href: String,
31}
32
33impl RedirectorProperties for LocationProperties {
34    fn children(&self) -> &Html {
35        &self.children
36    }
37}
38
39pub mod oauth2 {
40    //! Convenient access for the OAuth2 variant
41    use super::*;
42    use crate::agent::client::OAuth2Client as Client;
43    pub type LocationRedirect = Redirect<Client, LocationRedirector>;
44}
45
46#[cfg(feature = "openid")]
47pub mod openid {
48    //! Convenient access for the Open ID Connect variant
49    use super::*;
50    use crate::agent::client::OpenIdClient as Client;
51    pub type LocationRedirect = Redirect<Client, LocationRedirector>;
52}