Repository navigation
react-wallet-kit: add onOtpVerified callback - #1644
Open
sergeytimoshin wants to merge 1 commit into
Open
sergeytimoshin wants to merge 1 commit into
sergeytimoshin wants to merge 1 commit into
Conversation
Lets a host finish an email or SMS OTP login itself once the auth proxy has verified the code, instead of the SDK's account lookup and loginWithOtp/signUpWithOtp. The auth modal verifies the code, hands the verification token and the generated key pair's public key to callbacks.onOtpVerified, closes when it resolves, and shows the error and deletes the key pair when it rejects. Mirrors onOauthRedirect.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary & Motivation
Adds an optional
callbacks.onOtpVerifiedto@turnkey/react-wallet-kit. When it is set, the auth modal hands a verified email or SMS code over to the host instead of completing the login in the SDK (account lookup, thenloginWithOtporsignUpWithOtp). We build on Turnkey and finish OTP sign-ins through our own backend, and the SDK had no hook for that:onOauthRedirectalready hands an OAuth ID token to the host and skips the SDK's completion, so this is the same thing for OTP.Signature:
Semantics: the SDK generates the API key pair and verifies the code with the auth proxy (
verifyOtp), then awaits the callback with the verification token bound to the key pair's public key. The host finishes the login and stores the session it obtains withstoreSession. When the promise resolves the modal closes, as after a successful login. When it rejects, the modal shows the error like any other OTP error and the generated key pair is deleted. Without the callback nothing changes.Like
onOauthRedirect(consulted incompleteOAuthFlow, not incompleteOauth), the callback is consulted in the modal'sOtpVerificationpage only; callingcompleteOtpdirectly still completes the login in the SDK, and its return type is unchanged.callbacksis exposed on the client context as an@internalfield, next toconfig, so the page can read it.How I Tested These Changes
Added
src/tests/otp-test.tsx, which rendersOtpVerificationwith mocked hooks and checks the three paths: no callback (SDKcompleteOtp, modal closes), callback resolves (verifyOtpthen the callback with the expected params,completeOtpnot called, modal closes), callback rejects (error text shown,deleteApiKeyPaircalled, modal stays open), plus a failed verification never reaching the host.pnpm test,pnpm typecheck,pnpm buildandprettier --checkpass for the package, and the change is live in our app against a pnpm patch of the same logic.Did you add a changeset?
Yes, a minor bump for
@turnkey/react-wallet-kit.