Skip to content

Commit

Permalink
fix delete passkey
Browse files Browse the repository at this point in the history
  • Loading branch information
Giems committed Sep 18, 2024
1 parent 555b7c5 commit 5fbf0a8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sdk/packages/cloud/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/nightly-cloud",
"version": "0.0.20",
"version": "0.0.24",
"type": "module",
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/cloud/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export class NightlyCloud {
}

deletePasskey = async (request: HttpDeletePasskeyRequest): Promise<void> => {
await this.sendPostJson('/reset_passkey_finish', EndpointType.Public, request)
await this.sendPostJson('/delete_passkey', EndpointType.Private, request)
}

addNewPasskeyStart = async (): Promise<HttpAddNewPasskeyStartResponse> => {
Expand Down
9 changes: 5 additions & 4 deletions server/src/http/cloud/delete_passkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub async fn delete_passkey(
State(sessions_cache): State<Arc<ApiSessionsCache>>,
Extension(user_id): Extension<UserId>,
Json(payload): Json<HttpDeletePasskeyRequest>,
) -> Result<(), (StatusCode, String)> {
) -> Result<Json<()>, (StatusCode, String)> {
// Get cache data
let sessions_key = SessionsCacheKey::Passkey2FA(user_id.clone()).to_string();
let session_data = match sessions_cache.get(&sessions_key) {
Expand Down Expand Up @@ -64,10 +64,11 @@ pub async fn delete_passkey(
let user_data = match db.get_user_by_user_id(&user_id).await {
Ok(Some(user_data)) => user_data,
Ok(None) => {
error!("User does not exists: user_id: {}", user_id);
return Err((
StatusCode::BAD_REQUEST,
CloudApiErrors::UserDoesNotExist.to_string(),
))
));
}
Err(err) => {
error!(
Expand Down Expand Up @@ -110,7 +111,7 @@ pub async fn delete_passkey(
}

// Update user passkeys in database
if let Err(err) = db.update_passkeys(&user_id, &passkeys).await {
if let Err(err) = db.update_passkeys(&user_data.email, &passkeys).await {
error!(
"Failed to update user passkeys: {:?}, user_id: {}",
err, user_id
Expand All @@ -122,5 +123,5 @@ pub async fn delete_passkey(
));
}

return Ok(());
return Ok(Json(()));
}

0 comments on commit 5fbf0a8

Please sign in to comment.