Skip to content

Commit

Permalink
GraphQL API to use the new email authentication codes
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Jan 13, 2025
1 parent 063545f commit a807551
Show file tree
Hide file tree
Showing 6 changed files with 608 additions and 286 deletions.
3 changes: 2 additions & 1 deletion crates/handlers/src/graphql/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use self::{
oauth::{OAuth2Client, OAuth2Session},
site_config::{SiteConfig, SITE_CONFIG_ID},
upstream_oauth::{UpstreamOAuth2Link, UpstreamOAuth2Provider},
users::{AppSession, User, UserEmail, UserRecoveryTicket},
users::{AppSession, User, UserEmail, UserEmailAuthentication, UserRecoveryTicket},
viewer::{Anonymous, Viewer, ViewerSession},
};

Expand All @@ -42,6 +42,7 @@ pub enum CreationEvent {
CompatSession(Box<CompatSession>),
BrowserSession(Box<BrowserSession>),
UserEmail(Box<UserEmail>),
UserEmailAuthentication(Box<UserEmailAuthentication>),
UserRecoveryTicket(Box<UserRecoveryTicket>),
UpstreamOAuth2Provider(Box<UpstreamOAuth2Provider>),
UpstreamOAuth2Link(Box<UpstreamOAuth2Link>),
Expand Down
6 changes: 5 additions & 1 deletion crates/handlers/src/graphql/model/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ulid::Ulid;
use super::{
Anonymous, Authentication, BrowserSession, CompatSession, CompatSsoLogin, OAuth2Client,
OAuth2Session, SiteConfig, UpstreamOAuth2Link, UpstreamOAuth2Provider, User, UserEmail,
UserRecoveryTicket,
UserEmailAuthentication, UserRecoveryTicket,
};

#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand All @@ -27,6 +27,7 @@ pub enum NodeType {
UpstreamOAuth2Link,
User,
UserEmail,
UserEmailAuthentication,
UserRecoveryTicket,
}

Expand All @@ -52,6 +53,7 @@ impl NodeType {
NodeType::UpstreamOAuth2Link => "upstream_oauth2_link",
NodeType::User => "user",
NodeType::UserEmail => "user_email",
NodeType::UserEmailAuthentication => "user_email_authentication",
NodeType::UserRecoveryTicket => "user_recovery_ticket",
}
}
Expand All @@ -68,6 +70,7 @@ impl NodeType {
"upstream_oauth2_link" => Some(NodeType::UpstreamOAuth2Link),
"user" => Some(NodeType::User),
"user_email" => Some(NodeType::UserEmail),
"user_email_authentication" => Some(NodeType::UserEmailAuthentication),
"user_recovery_ticket" => Some(NodeType::UserRecoveryTicket),
_ => None,
}
Expand Down Expand Up @@ -124,5 +127,6 @@ pub enum Node {
UpstreamOAuth2Link(Box<UpstreamOAuth2Link>),
User(Box<User>),
UserEmail(Box<UserEmail>),
UserEmailAuthentication(Box<UserEmailAuthentication>),
UserRecoveryTicket(Box<UserRecoveryTicket>),
}
27 changes: 27 additions & 0 deletions crates/handlers/src/graphql/model/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,3 +850,30 @@ impl UserRecoveryTicket {
Ok(user_email.email)
}
}

/// A email authentication session
#[derive(Description)]
pub struct UserEmailAuthentication(pub mas_data_model::UserEmailAuthentication);

#[Object(use_type_description)]
impl UserEmailAuthentication {
/// ID of the object.
pub async fn id(&self) -> ID {
NodeType::UserEmailAuthentication.id(self.0.id)
}

/// When the object was created.
pub async fn created_at(&self) -> DateTime<Utc> {
self.0.created_at
}

/// When the object was last updated.
pub async fn completed_at(&self) -> Option<DateTime<Utc>> {
self.0.completed_at
}

/// The email address associated with this session
pub async fn email(&self) -> &str {
&self.0.email
}
}
Loading

0 comments on commit a807551

Please sign in to comment.