From f37d321525ac9c04bfb39803d6b81570fe699aef Mon Sep 17 00:00:00 2001 From: Rohit Sarpotdar Date: Thu, 21 Mar 2024 23:49:43 +0530 Subject: [PATCH] updated create resource to fix session refresh --- src/page/auth_init.rs | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/page/auth_init.rs b/src/page/auth_init.rs index 2bf4c3d..83a6a70 100644 --- a/src/page/auth_init.rs +++ b/src/page/auth_init.rs @@ -32,30 +32,30 @@ pub fn staging() -> impl IntoView { } Some(session) => { log!("session received: {}", session.len()); - let message = session.to_owned(); let session = session.to_owned(); - let resource = create_local_resource( + let _session_update = create_local_resource( move || session.clone(), - |session| update_session(session), + |session| async move { + let message_to_app = session.to_owned(); + match update_session(session).await { + Ok(()) => log!("session updated"), + Err(error) => error!("error in session update: {}", error), + } + let parent = + use_window().as_ref().unwrap().parent().unwrap().unwrap(); + match parent.post_message( + &JsValue::from_str(&message_to_app), + constants::APP_DOMAIN.as_str(), + ) { + Err(error) => error!( + "post result to app failed: {}", + error.as_string().unwrap_or("".to_owned()) + ), + Ok(_) => log!("session posted"), + } + }, ); - create_effect(move |_| match resource.get() { - Some(Ok(())) => {} - Some(Err(_)) => {} - None => {} - }); - - let parent = use_window().as_ref().unwrap().parent().unwrap().unwrap(); - match parent.post_message( - &JsValue::from_str(&message), - constants::APP_DOMAIN.as_str(), - ) { - Err(error) => error!( - "post result to app failed: {}", - error.as_string().unwrap_or("".to_owned()) - ), - Ok(_) => log!("session posted"), - } } None => { // no action @@ -104,6 +104,7 @@ pub async fn get_redirect_url() -> Result { Ok(url.as_str().to_owned()) } +// TODO: Verify signature before session update #[server] pub async fn update_session(session: String) -> Result<(), ServerFnError> { use crate::auth::{agent_js, cookie, identity::AppState};