Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix delete passkey #206

Merged
merged 1 commit into from
Sep 18, 2024
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
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(()));
}
Loading