Update openid example (#2474)
* Update openid example * Trim unnecessary deps * Update serve instructions * Remove unnecessary version in patch directive * Remove outdated workspace instructions * use storage signals instead of global signals with manual synchronization --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
1 parent
5494e38cf8
commit
054351139f
10 files changed
+6623
-306
No files matched your search
@@ -1,58 +1,36 @@
|
||||
#![allow(non_snake_case)]
|
||||
use dioxus::prelude::*;
|
||||
use fermi::*;
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
use log::LevelFilter;
|
||||
use dioxus_logger::tracing::Level;
|
||||
use router::Route;
|
||||
|
||||
use crate::oidc::ClientState;
|
||||
use crate::storage::{use_auth_request_provider, use_auth_token_provider};
|
||||
|
||||
pub(crate) mod constants;
|
||||
pub(crate) mod errors;
|
||||
pub(crate) mod model;
|
||||
pub(crate) mod oidc;
|
||||
pub(crate) mod props;
|
||||
pub(crate) mod router;
|
||||
pub(crate) mod storage;
|
||||
pub(crate) mod views;
|
||||
use oidc::{AuthRequestState, AuthTokenState};
|
||||
use router::Route;
|
||||
|
||||
use crate::{
|
||||
constants::{DIOXUS_FRONT_AUTH_REQUEST, DIOXUS_FRONT_AUTH_TOKEN},
|
||||
oidc::ClientState,
|
||||
};
|
||||
pub static FERMI_CLIENT: fermi::AtomRef<ClientState> = AtomRef(|_| ClientState::default());
|
||||
|
||||
// An option is required to prevent the component from being constantly refreshed
|
||||
pub static FERMI_AUTH_TOKEN: fermi::AtomRef<Option<AuthTokenState>> = AtomRef(|_| None);
|
||||
pub static FERMI_AUTH_REQUEST: fermi::AtomRef<Option<AuthRequestState>> = AtomRef(|_| None);
|
||||
pub static CLIENT: GlobalSignal<ClientState> = Signal::global(ClientState::default);
|
||||
|
||||
pub static DIOXUS_FRONT_ISSUER_URL: &str = env!("DIOXUS_FRONT_ISSUER_URL");
|
||||
pub static DIOXUS_FRONT_CLIENT_ID: &str = env!("DIOXUS_FRONT_CLIENT_ID");
|
||||
pub static DIOXUS_FRONT_CLIENT_SECRET: &str = env!("DIOXUS_FRONT_CLIENT_SECRET");
|
||||
pub static DIOXUS_FRONT_URL: &str = env!("DIOXUS_FRONT_URL");
|
||||
|
||||
fn App() -> Element {
|
||||
use_init_atom_root(cx);
|
||||
|
||||
// Retrieve the value stored in the browser's storage
|
||||
let stored_auth_token = LocalStorage::get(DIOXUS_FRONT_AUTH_TOKEN)
|
||||
.ok()
|
||||
.unwrap_or(AuthTokenState::default());
|
||||
let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
|
||||
if fermi_auth_token.read().is_none() {
|
||||
*fermi_auth_token.write() = Some(stored_auth_token);
|
||||
}
|
||||
|
||||
let stored_auth_request = LocalStorage::get(DIOXUS_FRONT_AUTH_REQUEST)
|
||||
.ok()
|
||||
.unwrap_or(AuthRequestState::default());
|
||||
let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
|
||||
if fermi_auth_request.read().is_none() {
|
||||
*fermi_auth_request.write() = Some(stored_auth_request);
|
||||
}
|
||||
use_auth_request_provider();
|
||||
use_auth_token_provider();
|
||||
rsx! { Router::<Route> {} }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
dioxus_logger::init(LevelFilter::Info).expect("failed to init logger");
|
||||
dioxus_logger::init(Level::DEBUG).expect("failed to init logger");
|
||||
dioxus_sdk::set_dir!();
|
||||
console_error_panic_hook::set_once();
|
||||
log::info!("starting app");
|
||||
dioxus_web::launch(App);
|
||||
launch(App);
|
||||
}
|
||||
Reference in new issue
Block a user