Skip to content

Commit

Permalink
remove redundant AuthenticatedUser
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbchron committed Feb 3, 2024
1 parent a3b8319 commit 5940452
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions crates/auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ use redact::Secret;
use serde::{Deserialize, Serialize};
use surrealdb::sql::Thing;

#[derive(Clone, Deserialize, Debug)]
pub struct AuthenticatedUser {
pub id: Thing,
pw_hash: Secret<String>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct User {
pub id: Thing,
Expand All @@ -17,16 +11,7 @@ pub struct User {
pub pw_hash: Secret<String>,
}

impl From<User> for AuthenticatedUser {
fn from(user: User) -> Self {
Self {
id: user.id,
pw_hash: user.pw_hash,
}
}
}

impl AuthUser for AuthenticatedUser {
impl AuthUser for User {
type Id = Thing;

fn id(&self) -> Self::Id { self.id.clone() }
Expand Down Expand Up @@ -57,7 +42,7 @@ impl Backend {

#[async_trait::async_trait]
impl AuthnBackend for Backend {
type User = AuthenticatedUser;
type User = User;
type Credentials = Credentials;
type Error = surrealdb::Error;

Expand All @@ -75,15 +60,15 @@ impl AuthnBackend for Backend {
.await?
.take(0)?;

Ok(user.map(AuthenticatedUser::from))
Ok(user)
}

async fn get_user(
&self,
user_id: &UserId<Self>,
) -> Result<Option<Self::User>, Self::Error> {
let user: Option<User> = (*self.surreal_client).select(user_id).await?;
Ok(user.map(AuthenticatedUser::from))
Ok(user)
}
}

Expand Down

0 comments on commit 5940452

Please sign in to comment.