Skip to main content

reinhardt_admin/server/
logout.rs

1//! Admin Logout Server Function
2//!
3//! Clears the admin authentication cookie to log out the user.
4
5use reinhardt_pages::server_fn::{ServerFnError, server_fn};
6
7#[cfg(not(target_arch = "wasm32"))]
8use super::security::build_admin_auth_cookie_clear;
9#[cfg(not(target_arch = "wasm32"))]
10use reinhardt_pages::server_fn::ServerFnRequest;
11
12/// Log out the current admin user by clearing the authentication cookie.
13///
14/// Sets a `Max-Age=0` cookie to instruct the browser to delete the
15/// `reinhardt_admin_token` cookie.
16///
17/// # Example
18///
19/// ```ignore
20/// use reinhardt_admin::server::logout::admin_logout;
21///
22/// admin_logout().await?;
23/// // Browser deletes the auth cookie, subsequent requests are unauthenticated
24/// ```
25#[server_fn]
26pub async fn admin_logout(#[inject] http_request: ServerFnRequest) -> Result<(), ServerFnError> {
27	let cookie = build_admin_auth_cookie_clear();
28	http_request.add_response_cookie(cookie);
29	Ok(())
30}