Skip to content

Commit

Permalink
Merge pull request #80 from go-bazzinga/login-system-workflow-change
Browse files Browse the repository at this point in the history
updated create resource to fix session refresh
  • Loading branch information
rosarp-gobazzinga authored Mar 21, 2024
2 parents 378c6e8 + f37d321 commit 54e8249
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/page/auth_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -104,6 +104,7 @@ pub async fn get_redirect_url() -> Result<String, ServerFnError> {
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};
Expand Down

0 comments on commit 54e8249

Please sign in to comment.