Return error on /api/signup if signup disabled

This commit is contained in:
Ethan Girouard 2024-11-24 14:36:56 -05:00
parent 6592d66f87
commit 5ecb71ce9d
Signed by: eta357
GPG Key ID: 7BCDC36DFD11C146

View File

@ -19,6 +19,11 @@ use crate::users::UserCredentials;
/// Returns a Result with the error message if the user could not be created
#[server(endpoint = "signup")]
pub async fn signup(new_user: User) -> Result<(), ServerFnError> {
// Check LIBRETUNES_DISABLE_SIGNUP env var
if std::env::var("LIBRETUNES_DISABLE_SIGNUP").is_ok_and(|v| v == "true") {
return Err(ServerFnError::<NoCustomError>::ServerError("Signup is disabled".to_string()));
}
use crate::users::create_user;
// Ensure the user has no id, and is not a self-proclaimed admin