Skip to content

Commit 6ca1410

Browse files
committed
refactor(user): call increment_generation_id from set_password
Signed-off-by: stadust <[email protected]>
1 parent 13503dc commit 6ca1410

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use sqlx::PgConnection;
2+
3+
use crate::auth::legacy::LegacyAuthenticatedUser;
4+
use crate::Result;
5+
6+
use super::{ValidatedGoogleCredentials};
7+
8+
impl LegacyAuthenticatedUser {
9+
pub async fn set_linked_google_account(&mut self, creds: &ValidatedGoogleCredentials, connection: &mut PgConnection) -> Result<()> {
10+
sqlx::query!(
11+
"UPDATE members SET google_account_id = $1 WHERE member_id = $2",
12+
creds.google_account_id(),
13+
self.user().id
14+
)
15+
.execute(connection)
16+
.await?;
17+
18+
Ok(())
19+
}
20+
}

pointercrate-user/src/auth/patch.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ impl AuthenticatedUser<PasswordOrBrowser> {
5050
}
5151

5252
self.set_password(password, connection).await?;
53-
54-
// needed to invalidate existing access tokens
55-
self.increment_generation_id(connection).await?;
5653
}
5754

5855
self.into_user()
@@ -69,9 +66,12 @@ impl AuthenticatedUser<PasswordOrBrowser> {
6966

7067
async fn set_password(&mut self, password: String, connection: &mut PgConnection) -> Result<()> {
7168
match &mut self.auth_type {
72-
AuthenticationType::Legacy(legacy) => legacy.set_password(password, connection).await,
73-
_ => Err(UserError::NonLegacyAccount),
69+
AuthenticationType::Legacy(legacy) => legacy.set_password(password, connection).await?,
70+
_ => return Err(UserError::NonLegacyAccount),
7471
}
72+
73+
// needed to invalidate existing access tokens
74+
self.increment_generation_id(connection).await
7575
}
7676

7777
pub(super) async fn increment_generation_id(&mut self, connection: &mut PgConnection) -> Result<()> {

0 commit comments

Comments
 (0)