mod accounts;
mod sessions;
mod users;
mod verifications;
mod api_keys;
mod device_codes;
mod invitations;
mod jwks;
mod members;
mod optional_records;
mod organizations;
mod roles;
mod teams;
mod transaction;
use super::*;
use crate::{AccountView, SessionView, UserView, VerificationView};
use chrono::{DateTime, Utc};
pub struct StatelessSchema;
impl AuthSchema for StatelessSchema {
fn user_from_cookie_cache(user: UserView) -> Option<UserView> {
Some(user)
}
type User = UserView;
type Session = SessionView;
type Account = AccountView;
type Verification = VerificationView;
}
pub struct StatelessStore {
state: std::sync::Mutex<IdentityState>,
organizations: std::sync::Mutex<OrganizationState>,
find_many_limit: usize,
}
#[derive(Default)]
struct IdentityState {
users: indexmap::IndexMap<String, UserView>,
accounts: indexmap::IndexMap<String, AccountView>,
verifications: indexmap::IndexMap<String, VerificationView>,
two_factors: indexmap::IndexMap<String, TwoFactor>,
passkeys: indexmap::IndexMap<String, Passkey>,
api_keys: indexmap::IndexMap<String, ApiKey>,
device_codes: indexmap::IndexMap<String, DeviceCode>,
jwks: indexmap::IndexMap<String, Jwk>,
}
#[derive(Default, Clone)]
struct OrganizationState {
organizations: indexmap::IndexMap<String, Organization>,
members: indexmap::IndexMap<String, Member>,
invitations: indexmap::IndexMap<String, Invitation>,
teams: indexmap::IndexMap<String, Team>,
team_members: indexmap::IndexMap<String, TeamMember>,
roles: indexmap::IndexMap<String, OrganizationRole>,
}
impl Default for StatelessStore {
fn default() -> Self {
Self::with_find_many_limit(100)
}
}
impl StatelessStore {
#[must_use]
pub fn with_find_many_limit(find_many_limit: usize) -> Self {
Self {
state: Default::default(),
organizations: Default::default(),
find_many_limit,
}
}
fn organization_state(&self) -> AuthResult<std::sync::MutexGuard<'_, OrganizationState>> {
self.organizations
.lock()
.map_err(|_| AuthError::internal("No-database organization state poisoned"))
}
fn lock(&self) -> AuthResult<std::sync::MutexGuard<'_, IdentityState>> {
self.state
.lock()
.map_err(|_| AuthError::internal("No-database identity state poisoned"))
}
}
impl WalletAddressStore for StatelessStore {}