use serde::{Deserialize, Serialize};
use torii::{Session, User};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisterRequest {
pub email: String,
pub password: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoginRequest {
pub email: String,
pub password: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChangePasswordRequest {
pub old_password: String,
pub new_password: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MagicLinkRequest {
pub email: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerifyMagicTokenRequest {
pub token: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PasswordResetRequest {
pub email: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerifyResetTokenRequest {
pub token: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResetPasswordRequest {
pub token: String,
pub new_password: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct AuthResponse {
pub user: User,
pub session: Session,
}
#[derive(Debug, Clone, Serialize)]
pub struct UserResponse {
pub user: User,
}
#[derive(Debug, Clone, Serialize)]
pub struct SessionResponse {
pub session: Session,
}
#[derive(Debug, Clone, Serialize)]
pub struct MessageResponse {
pub message: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct MagicLinkResponse {
pub message: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct PasswordResetResponse {
pub message: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct VerifyResetTokenResponse {
pub valid: bool,
}
#[derive(Debug, Clone, Serialize)]
pub struct HealthResponse {
pub status: String,
pub version: String,
}
#[derive(Debug, Clone)]
pub struct ConnectionInfo {
pub ip: Option<String>,
pub user_agent: Option<String>,
}
#[derive(Debug, Clone)]
pub struct CookieConfig {
pub name: String,
pub http_only: bool,
pub secure: bool,
pub same_site: CookieSameSite,
pub path: String,
}
impl Default for CookieConfig {
fn default() -> Self {
Self {
name: "session_id".to_string(),
http_only: true,
secure: true,
same_site: CookieSameSite::Lax,
path: "/".to_string(),
}
}
}
#[derive(Debug, Clone)]
pub enum CookieSameSite {
Strict,
Lax,
None,
}
#[derive(Debug, Clone)]
pub struct LinkConfig {
pub hostname: String,
pub path_prefix: String,
}
impl LinkConfig {
pub fn new(hostname: impl Into<String>) -> Self {
Self {
hostname: hostname.into(),
path_prefix: "/auth".to_string(),
}
}
pub fn with_path_prefix(mut self, prefix: impl Into<String>) -> Self {
self.path_prefix = prefix.into();
self
}
pub fn magic_link_url(&self, token: &str) -> String {
format!(
"{}{}/magic-link/verify?token={}",
self.hostname.trim_end_matches('/'),
self.path_prefix,
token
)
}
pub fn password_reset_url(&self, token: &str) -> String {
format!(
"{}{}/password/reset?token={}",
self.hostname.trim_end_matches('/'),
self.path_prefix,
token
)
}
}
impl Default for CookieSameSite {
fn default() -> Self {
Self::Lax
}
}
impl CookieConfig {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
http_only: true,
secure: true,
same_site: CookieSameSite::Lax,
path: "/".to_string(),
}
}
pub fn development() -> Self {
Self {
name: "session_id".to_string(),
http_only: true,
secure: false,
same_site: CookieSameSite::Lax,
path: "/".to_string(),
}
}
}