Skip to content

Commit

Permalink
added error handling to MSA authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Jun 4, 2023
1 parent 655a5f6 commit f46e0ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src-tauri/src/app/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,20 @@ async fn login_offline(username: &str) -> Result<Account, String> {
fn login_microsoft(window: tauri::Window) -> Result<(), String> {
// todo: rewrite library async
thread::spawn(move || {
let account = service::auth_msa(|code| {
match service::auth_msa(|code| {
info!("received code: {}", code);

let _ = window.emit("microsoft_code", code);
}).unwrap(); // unwrap is fine cuz own thread

let _ = window.emit("microsoft_successful", account);
}) {
Ok(account) => {
info!("successfully logged in with microsoft account: {:?}", account);
let _ = window.emit("microsoft_successful", account);
}
Err(e) => {
error!("unable to login with microsoft account: {:?}", e);
let _ = window.emit("microsoft_error", format!("unable to login with microsoft account: {:?}", e));
}
}
});

Ok(())
Expand Down
5 changes: 5 additions & 0 deletions src/lib/login/loginmodal/LoginModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
options.store();
});
listen("microsoft_error", (e) => {
alert(e.payload);
console.debug("microsoft_error", e.payload);
});
function linkMicrosoftOpen() {
invoke("open_url", { url: "https://microsoft.com/link" })
}
Expand Down

0 comments on commit f46e0ed

Please sign in to comment.