feat(account settings): Add signout functionality (#16)

* Create account.vue with logout button

* Update auth.rs to add signout command

* Update lib.rs to pass sign_out command to frontend
This commit is contained in:
Aden Lindsay
2025-01-01 12:53:18 +10:30
committed by GitHub
parent a17311a88d
commit 0a0d9d6294
3 changed files with 100 additions and 1 deletions

View File

@ -232,3 +232,29 @@ pub fn setup() -> Result<(AppStatus, Option<User>), ()> {
Ok((AppStatus::SignedOut, None))
}
#[tauri::command]
pub fn sign_out(app: AppHandle) -> Result<(), String> {
info!("Signing out user");
// Clear auth from database
{
let mut handle = DB.borrow_data_mut().unwrap();
handle.auth = None;
drop(handle);
DB.save().unwrap();
}
// Update app state
{
let app_state = app.state::<Mutex<AppState>>();
let mut app_state_handle = app_state.lock().unwrap();
app_state_handle.status = AppStatus::SignedOut;
app_state_handle.user = None;
}
// Emit event for frontend
app.emit("auth/signedout", ()).unwrap();
Ok(())
}

View File

@ -12,7 +12,7 @@ mod tests;
mod autostart;
use crate::db::DatabaseImpls;
use auth::{auth_initiate, generate_authorization_header, manual_recieve_handshake, recieve_handshake, retry_connect};
use auth::{auth_initiate, generate_authorization_header, manual_recieve_handshake, recieve_handshake, retry_connect, sign_out};
use cleanup::{cleanup_and_exit, quit};
use db::{
add_download_dir, delete_download_dir, fetch_download_dir_stats, DatabaseInterface, GameStatus,
@ -221,6 +221,7 @@ pub fn run() {
auth_initiate,
retry_connect,
manual_recieve_handshake,
sign_out,
// Remote
use_remote,
gen_drop_url,