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

Helper to find the RP ID given users' devices and current origin #2729

Merged
merged 6 commits into from
Dec 6, 2024

Conversation

lmuntaner
Copy link
Collaborator

@lmuntaner lmuntaner commented Dec 5, 2024

Motivation

We want to support user registering in multiple domains as well as logging in them.

In this PR, I introduce a helper to find the RP ID given a set of devices and current origin.

Changes

  • New helper findWebAuthnRpId.

Tests

  • Test helper extensively.

🟡 Some screens were changed

@lmuntaner lmuntaner marked this pull request as ready for review December 5, 2024 12:58
@lmuntaner lmuntaner requested a review from a team as a code owner December 5, 2024 12:58
@lmuntaner lmuntaner requested review from sea-snake and LXIF December 5, 2024 12:59
@lmuntaner
Copy link
Collaborator Author

@LXIF @sea-snake please review

Copy link
Contributor

@LXIF LXIF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, tests pass locally as well. Great work!

src/frontend/src/utils/findWebAuthnRpId.ts Outdated Show resolved Hide resolved
src/frontend/src/utils/findWebAuthnRpId.ts Outdated Show resolved Hide resolved
src/frontend/src/utils/findWebAuthnRpId.ts Outdated Show resolved Hide resolved
src/frontend/src/utils/findWebAuthnRpId.ts Outdated Show resolved Hide resolved
"Not possible. Devices must be registered for at least one of the following domains: ic0.app, internetcomputer.org, icp0.io"
);
} catch (error) {
console.error(error);
Copy link
Contributor

@sea-snake sea-snake Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of wrapping the whole findWebAuthnRpId function in a try/catch just to console log any errors, maybe the caller of findWebAuthnRpId can console log the error instead to avoid the need for the try/catch?

Since re-throwing an error from a catch block is considered an anti pattern as far as I'm aware.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I initially added it wanting to return something different. But then I decided against it and the try/catch was left. I'll remove it.

@lmuntaner lmuntaner force-pushed the lm-determine-web-auth-rp-id branch from 9c75fce to 9cb4f27 Compare December 6, 2024 12:06
@lmuntaner lmuntaner requested review from sea-snake and LXIF December 6, 2024 12:07
@lmuntaner
Copy link
Collaborator Author

lmuntaner commented Dec 6, 2024

Looks good, tests pass locally as well. Great work!

Thanks! Did you wanted to add a comment only or approve the PR?

@LXIF
Copy link
Contributor

LXIF commented Dec 6, 2024

Looks good, tests pass locally as well. Great work!

Thanks! Did you wanted to add a comment only or approve the PR?

My bad, friday brained. Approved now.

@lmuntaner lmuntaner added this pull request to the merge queue Dec 6, 2024
github-merge-queue bot pushed a commit that referenced this pull request Dec 6, 2024
* Helper to determine the webauthn RP ID

* Improve tests

* Rename

* Improve comments

* Apply suggestions from code review

Co-authored-by: sea-snake <[email protected]>

* Remove try/catch

---------

Co-authored-by: sea-snake <[email protected]>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 6, 2024
@lmuntaner lmuntaner added this pull request to the merge queue Dec 6, 2024
Merged via the queue into main with commit 19a1dea Dec 6, 2024
67 checks passed
@lmuntaner lmuntaner deleted the lm-determine-web-auth-rp-id branch December 6, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants