-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogout.rs
47 lines (42 loc) · 1.35 KB
/
logout.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Handles user logout operations
use tracing::{debug, error, instrument, trace_span, Instrument};
use crate::util::handle_response_code;
use crate::{AuthClient, AuthError};
impl AuthClient {
/// Logs out a user by invalidating their token
///
/// # Arguments
/// * `token` - The access token to invalidate
///
/// # Returns
/// * `Result<(), AuthError>` - Success or error
#[instrument(skip_all)]
pub async fn logout(&self, token: &str) -> Result<(), AuthError> {
let resp = match self
.http_client
.post(format!("{}/auth/v1/{}", self.supabase_api_url, "logout"))
.bearer_auth(token)
.header("apiKey", &self.supabase_anon_key)
.send()
.instrument(trace_span!("gotrue logout user"))
.await
{
Ok(resp) => resp,
Err(e) => {
error!("{}", e);
return Err(AuthError::Http);
}
};
let resp_code_result = handle_response_code(resp.status()).await;
let resp_text = match resp.text().await {
Ok(resp_text) => resp_text,
Err(e) => {
log::error!("{}", e);
return Err(AuthError::Http);
}
};
debug!("resp_text: {}", resp_text);
resp_code_result?;
Ok(())
}
}