Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions crates/defguard_core/src/db/models/biometric_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ impl BiometricAuth<Id> {
.fetch_optional(executor)
.await
}

pub(crate) async fn find_by_user_id<'e, E>(
executor: E,
user_id: Id,
) -> Result<Vec<Self>, sqlx::Error>
where
E: PgExecutor<'e>,
{
query_as!(
Self,
"SELECT b.id, b.pub_key, b.device_id FROM biometric_auth as b JOIN device d ON b.device_id = d.id WHERE d.user_id = $1", &user_id
)
.fetch_all(executor)
.await
}
}

#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/defguard_core/src/db/models/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct DeviceConfig {

// The type of a device:
// User: A device of a user, which may be in multiple networks, e.g. a laptop
// Network: A standalone device added by a user permamently bound to one network, e.g. a printer
// Network: A stand-alone device added by a user permanently bound to one network, e.g. a printer
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, ToSchema, Type)]
#[sqlx(type_name = "device_type", rename_all = "snake_case")]
pub enum DeviceType {
Expand Down
10 changes: 9 additions & 1 deletion crates/defguard_core/src/db/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use std::collections::HashSet;
use sqlx::{Error as SqlxError, PgConnection, PgPool, query_as};
use utoipa::ToSchema;

use crate::db::models::biometric_auth::BiometricAuth;

use self::{
device::UserDevice,
user::{MFAMethod, User},
Expand Down Expand Up @@ -204,6 +206,7 @@ pub struct UserDetails {
pub user: UserInfo,
#[serde(default)]
pub devices: Vec<UserDevice>,
pub biometric_enabled_devices: Vec<i64>,
#[serde(default)]
pub security_keys: Vec<SecurityKey>,
}
Expand All @@ -212,11 +215,16 @@ impl UserDetails {
pub async fn from_user(pool: &PgPool, user: &User<Id>) -> Result<Self, SqlxError> {
let devices = user.user_devices(pool).await?;
let security_keys = user.security_keys(pool).await?;

let biometric_enabled_devices = BiometricAuth::find_by_user_id(pool, user.id)
.await?
.iter()
.map(|a| a.device_id)
.collect::<Vec<_>>();
Ok(Self {
user: UserInfo::from_user(pool, user).await?,
devices,
security_keys,
biometric_enabled_devices,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion web/biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.1.1/schema.json",
"$schema": "https://biomejs.dev/schemas/2.1.3/schema.json",
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
"files": {
"ignoreUnknown": false,
Expand Down
4 changes: 2 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
},
"devDependencies": {
"@babel/core": "^7.28.0",
"@biomejs/biome": "2.1.1",
"@biomejs/biome": "2.1.3",
"@csstools/css-parser-algorithms": "^3.0.5",
"@csstools/css-tokenizer": "^3.0.4",
"@hookform/devtools": "^4.4.0",
Expand All @@ -139,7 +139,7 @@
"sass": "~1.70.0",
"standard-version": "^9.5.0",
"type-fest": "^4.41.0",
"typescript": "~5.8.3",
"typescript": "~5.9.2",
"vite": "^7.0.6",
"vite-plugin-package-version": "^1.1.0"
}
Expand Down
100 changes: 50 additions & 50 deletions web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading