1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Have a better error on registration if the username is already taken

This commit is contained in:
Quentin Gliech
2022-05-23 14:36:38 +02:00
parent dd8eea7da3
commit bfc20b6faa
5 changed files with 45 additions and 2 deletions

View File

@ -476,6 +476,22 @@ pub async fn lookup_user_by_username(
})
}
pub async fn username_exists(
executor: impl PgExecutor<'_>,
username: &str,
) -> Result<bool, sqlx::Error> {
sqlx::query_scalar!(
r#"
SELECT EXISTS(
SELECT 1 FROM users WHERE username = $1
) AS "exists!"
"#,
username
)
.fetch_one(executor)
.await
}
#[derive(Debug, Clone)]
struct UserEmailLookup {
user_email_id: i64,