#Failing to understand invoke usage - Crashing app

27 messages ยท Page 1 of 1 (latest)

tight ferry
#

it's failing when inputting wrong credentials

let handle_submit = move |ev: SubmitEvent| {
        ev.prevent_default();

        spawn_local(async move {
            let email = email.get_untracked();
            let password = password.get_untracked();

            let args = LoginArgs {
                email: &email,
                password: &password,
            };

            let js_args = match serde_wasm_bindgen::to_value(&args) {
                Ok(val) => val,
                Err(err) => {
                    set_message.set(Some(format!("Failed to serialize args: {:?}", err)));
                    return;
                }
            };

            let result = invoke("login", js_args).await;

            if result.is_undefined() {
                //navigate
            } else {
                match serde_wasm_bindgen::from_value::<String>(result) {
                    Ok(err_msg) => set_message.set(Some(err_msg)),
                    Err(e) => set_message.set(Some(format!("Unexpected error: {:?}", e))),
                }
            }
        });
    };
#[tauri::command]
async fn login(email: String, password: String) -> Result<(), String> {
    if email == "[email protected]" && password == "oguielindo" {
        Ok(())
    } else {
        Err("Invalid credentials".to_string())
    }
}
shy cape
#

what does your invoke function look like?

#

or is that tauri-sys? In that case, maybe try invoke_result

tight ferry
# shy cape or is that tauri-sys? In that case, maybe try invoke_result

my invoke is what's on the docs the

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
    // invoke without arguments
    #[wasm_bindgen(js_namespace = ["window", "__TAURI__", "core"], js_name = invoke)]
    pub async fn invoke_without_args(cmd: &str) -> JsValue;

    // invoke with arguments (default)
    #[wasm_bindgen(js_namespace = ["window", "__TAURI__", "core"])]
    pub async fn invoke(cmd: &str, args: JsValue) -> JsValue;

    // They need to have different names!
}
#

i've been banging my head on the table

shy cape
#

try this then ```rs
#[wasm_bindgen(js_name = "invoke", catch)]
pub async fn invoke_result(cmd: &str, args: JsValue) -> Result<JsValue, JsValue>;

#

this is what tauri-sys uses

tight ferry
tight ferry
#

i'm not being able to allow the tauri module of the taurii-sys crate even though i put features = ["all"]

tight ferry
#

to make tauri::inovke

shy cape
#

i did not work with it (or rust frontends) myself yet though so i can't really help with the issue you have i think

tight ferry
#

I really liked dioxus but since it doesn't support full bundle with app icons and stuff I ended up coming to Tauri + Leptos

shy cape
#

ah maybe i lied, there's no tauri module, there's just core

#

so tauri_sys::core::invoke / tauri_sys::core::invoke_result

tight ferry
#

i get the same problem

#

unexpected exception: JsValue("invalid_credentials")

shy cape
#

same with invoke and invoke_result?

tight ferry
#

i only used invoke let me try invoke_result

btw

this will kinda make me look bad but I can't no longer think

tauri-sys is to put on frontend cargo.toml or tauri's cargo.toml?

shy cape
#

frontend

tight ferry
#

like i already had it ๐Ÿ˜ญ

tight ferry
#

invoke_result worked

shy cape
#

i'm glad, i really had no other idea ๐Ÿ˜