Skip to content

Commit 23b019c

Browse files
committed
GraphQL API to use the new email authentication codes
1 parent 5f5fc44 commit 23b019c

File tree

6 files changed

+608
-286
lines changed

6 files changed

+608
-286
lines changed

crates/handlers/src/graphql/model/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use self::{
2626
oauth::{OAuth2Client, OAuth2Session},
2727
site_config::{SiteConfig, SITE_CONFIG_ID},
2828
upstream_oauth::{UpstreamOAuth2Link, UpstreamOAuth2Provider},
29-
users::{AppSession, User, UserEmail, UserRecoveryTicket},
29+
users::{AppSession, User, UserEmail, UserEmailAuthentication, UserRecoveryTicket},
3030
viewer::{Anonymous, Viewer, ViewerSession},
3131
};
3232

@@ -42,6 +42,7 @@ pub enum CreationEvent {
4242
CompatSession(Box<CompatSession>),
4343
BrowserSession(Box<BrowserSession>),
4444
UserEmail(Box<UserEmail>),
45+
UserEmailAuthentication(Box<UserEmailAuthentication>),
4546
UserRecoveryTicket(Box<UserRecoveryTicket>),
4647
UpstreamOAuth2Provider(Box<UpstreamOAuth2Provider>),
4748
UpstreamOAuth2Link(Box<UpstreamOAuth2Link>),

crates/handlers/src/graphql/model/node.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use ulid::Ulid;
1212
use super::{
1313
Anonymous, Authentication, BrowserSession, CompatSession, CompatSsoLogin, OAuth2Client,
1414
OAuth2Session, SiteConfig, UpstreamOAuth2Link, UpstreamOAuth2Provider, User, UserEmail,
15-
UserRecoveryTicket,
15+
UserEmailAuthentication, UserRecoveryTicket,
1616
};
1717

1818
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -27,6 +27,7 @@ pub enum NodeType {
2727
UpstreamOAuth2Link,
2828
User,
2929
UserEmail,
30+
UserEmailAuthentication,
3031
UserRecoveryTicket,
3132
}
3233

@@ -52,6 +53,7 @@ impl NodeType {
5253
NodeType::UpstreamOAuth2Link => "upstream_oauth2_link",
5354
NodeType::User => "user",
5455
NodeType::UserEmail => "user_email",
56+
NodeType::UserEmailAuthentication => "user_email_authentication",
5557
NodeType::UserRecoveryTicket => "user_recovery_ticket",
5658
}
5759
}
@@ -68,6 +70,7 @@ impl NodeType {
6870
"upstream_oauth2_link" => Some(NodeType::UpstreamOAuth2Link),
6971
"user" => Some(NodeType::User),
7072
"user_email" => Some(NodeType::UserEmail),
73+
"user_email_authentication" => Some(NodeType::UserEmailAuthentication),
7174
"user_recovery_ticket" => Some(NodeType::UserRecoveryTicket),
7275
_ => None,
7376
}
@@ -124,5 +127,6 @@ pub enum Node {
124127
UpstreamOAuth2Link(Box<UpstreamOAuth2Link>),
125128
User(Box<User>),
126129
UserEmail(Box<UserEmail>),
130+
UserEmailAuthentication(Box<UserEmailAuthentication>),
127131
UserRecoveryTicket(Box<UserRecoveryTicket>),
128132
}

crates/handlers/src/graphql/model/users.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,3 +850,30 @@ impl UserRecoveryTicket {
850850
Ok(user_email.email)
851851
}
852852
}
853+
854+
/// A email authentication session
855+
#[derive(Description)]
856+
pub struct UserEmailAuthentication(pub mas_data_model::UserEmailAuthentication);
857+
858+
#[Object(use_type_description)]
859+
impl UserEmailAuthentication {
860+
/// ID of the object.
861+
pub async fn id(&self) -> ID {
862+
NodeType::UserEmailAuthentication.id(self.0.id)
863+
}
864+
865+
/// When the object was created.
866+
pub async fn created_at(&self) -> DateTime<Utc> {
867+
self.0.created_at
868+
}
869+
870+
/// When the object was last updated.
871+
pub async fn completed_at(&self) -> Option<DateTime<Utc>> {
872+
self.0.completed_at
873+
}
874+
875+
/// The email address associated with this session
876+
pub async fn email(&self) -> &str {
877+
&self.0.email
878+
}
879+
}

0 commit comments

Comments
 (0)