grafbase_local_backend/api/
logout.rs1use super::{consts::CREDENTIALS_FILE, errors::ApiError};
2use common::environment::get_user_dot_grafbase_path;
3use std::fs;
4
5pub fn logout() -> Result<(), ApiError> {
15 let user_dot_grafbase_path = get_user_dot_grafbase_path().ok_or(ApiError::NotLoggedIn)?;
16
17 let credentials_path = user_dot_grafbase_path.join(CREDENTIALS_FILE);
18
19 match credentials_path.try_exists() {
20 Ok(true) => fs::remove_file(credentials_path).map_err(ApiError::DeleteCredentialsFile),
21 Ok(false) => Err(ApiError::NotLoggedIn),
22 Err(error) => Err(ApiError::ReadCredentialsFile(error)),
23 }
24}