use async_trait::async_trait;
use shield::{
Form, Input, InputType, InputTypeEmail, InputTypeHidden, InputTypePassword, InputTypeSubmit,
InputValue, MethodAction, MethodSession, Request, RequestMethod, Response, ResponseType,
ShieldError, SignUpAction, erased_method_action,
};
use workos::Client;
use crate::provider::WorkosProvider;
pub struct WorkosSignUpAction {
#[expect(unused)]
client: Client,
}
impl WorkosSignUpAction {
pub fn new(client: Client) -> Self {
Self { client }
}
}
#[async_trait]
impl MethodAction<WorkosProvider, ()> for WorkosSignUpAction {
fn id(&self) -> String {
SignUpAction::id()
}
fn name(&self) -> String {
SignUpAction::name()
}
fn openapi_summary(&self) -> &'static str {
"Sign up with WorkOS"
}
fn openapi_description(&self) -> &'static str {
"Sign up with WorkOS."
}
fn method(&self) -> RequestMethod {
RequestMethod::Post
}
async fn forms(&self, _provider: WorkosProvider) -> Result<Vec<Form>, ShieldError> {
Ok(vec![
Form {
inputs: vec![
Input {
name: "email".to_owned(),
label: Some("Email address".to_owned()),
r#type: InputType::Email(InputTypeEmail {
autocomplete: Some("email".to_owned()),
placeholder: Some("Email address".to_owned()),
required: Some(true),
..Default::default()
}),
value: None,
addon_start: None,
addon_end: None,
},
Input {
name: "password".to_owned(),
label: Some("Password".to_owned()),
r#type: InputType::Password(InputTypePassword {
autocomplete: Some("new-password".to_owned()),
placeholder: Some("Password".to_owned()),
required: Some(true),
..Default::default()
}),
value: None,
addon_start: None,
addon_end: None,
},
Input {
name: "submit".to_owned(),
label: None,
r#type: InputType::Submit(InputTypeSubmit::default()),
value: Some(InputValue::String {
value: "Sign up".to_owned(),
}),
addon_start: None,
addon_end: None,
},
],
},
Form {
inputs: vec![
Input {
name: "email".to_owned(),
label: None,
r#type: InputType::Hidden(InputTypeHidden {
autocomplete: Some("email".to_owned()),
required: Some(true),
}),
value: None,
addon_start: None,
addon_end: None,
},
Input {
name: "submit".to_owned(),
label: None,
r#type: InputType::Submit(InputTypeSubmit::default()),
value: Some(InputValue::String {
value: "Email sign-up code".to_owned(),
}),
addon_start: None,
addon_end: None,
},
],
},
])
}
async fn call(
&self,
_provider: WorkosProvider,
_session: &MethodSession<()>,
_request: Request,
) -> Result<Response, ShieldError> {
Ok(Response::new(ResponseType::Default))
}
}
erased_method_action!(WorkosSignUpAction);