rustauth_plugins/multi_session/
mod.rs1mod cookies;
4mod endpoints;
5mod errors;
6mod hooks;
7mod options;
8
9pub use errors::{INVALID_SESSION_TOKEN, MULTI_SESSION_ERROR_CODES};
10pub use options::{MultiSessionOptions, MultiSessionOptionsBuilder};
11
12use rustauth_core::plugin::{AuthPlugin, PluginErrorCode};
13
14pub const UPSTREAM_PLUGIN_ID: &str = "multi-session";
15
16#[must_use]
17pub fn multi_session(config: MultiSessionOptions) -> AuthPlugin {
18 AuthPlugin::new(UPSTREAM_PLUGIN_ID)
19 .with_version(crate::VERSION)
20 .with_options(serde_json::json!({
21 "maximumSessions": config.maximum_sessions,
22 }))
23 .with_error_code(PluginErrorCode::new(
24 INVALID_SESSION_TOKEN,
25 "Invalid session token",
26 ))
27 .with_endpoint(endpoints::list_device_sessions_endpoint())
28 .with_endpoint(endpoints::set_active_session_endpoint())
29 .with_endpoint(endpoints::revoke_device_session_endpoint())
30 .with_async_after_hook("*", hooks::store_multi_session_cookie(config))
31 .with_async_after_hook("/sign-out", hooks::revoke_multi_session_cookies())
32}