From 9f0543f0dc3a6a67c725921389778873923ead6c Mon Sep 17 00:00:00 2001 From: Michael Moldoveanu Date: Thu, 14 Nov 2024 13:59:43 -0500 Subject: [PATCH] fix(signer): passkey sessions were being wiped by oauth prep (#1154) --- account-kit/signer/src/client/index.ts | 7 ++++++- account-kit/signer/src/session/manager.ts | 1 + account-kit/smart-contracts/package.json | 2 +- .../ui-demo/src/components/shared/mint-card/MintCard.tsx | 3 ++- turbo.json | 5 ----- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/account-kit/signer/src/client/index.ts b/account-kit/signer/src/client/index.ts index c4f0a80d5a..f7d4409be7 100644 --- a/account-kit/signer/src/client/index.ts +++ b/account-kit/signer/src/client/index.ts @@ -3,6 +3,7 @@ import { getWebAuthnAttestation } from "@turnkey/http"; import { IframeStamper } from "@turnkey/iframe-stamper"; import { WebauthnStamper } from "@turnkey/webauthn-stamper"; import { z } from "zod"; +import { OAuthProvidersError } from "../errors.js"; import { getDefaultScopeAndClaims, getOauthNonce } from "../oauth.js"; import type { AuthParams, OauthMode } from "../signer.js"; import { base64UrlEncode } from "../utils/base64UrlEncode.js"; @@ -19,7 +20,6 @@ import type { OauthParams, User, } from "./types.js"; -import { OAuthProvidersError } from "../errors.js"; const CHECK_CLOSE_INTERVAL = 500; @@ -304,6 +304,7 @@ export class AlchemySignerWebClient extends BaseSignerClient await this.initWebauthnStamper(user); if (user) { this.user = user; + this.eventEmitter.emit("connectedPasskey", user); return user; } @@ -665,7 +666,11 @@ export class AlchemySignerWebClient extends BaseSignerClient }; protected override getOauthConfig = async (): Promise => { + const currentStamper = this.turnkeyClient.stamper; const publicKey = await this.initIframeStamper(); + + // swap the stamper back in case the user logged in with a different stamper (passkeys) + this.setStamper(currentStamper); const nonce = getOauthNonce(publicKey); return this.request("/v1/prepare-oauth", { nonce }); }; diff --git a/account-kit/signer/src/session/manager.ts b/account-kit/signer/src/session/manager.ts index 97766a9825..cf003e7191 100644 --- a/account-kit/signer/src/session/manager.ts +++ b/account-kit/signer/src/session/manager.ts @@ -96,6 +96,7 @@ export class SessionManager { orgId: existingSession.user.orgId, authenticatingType: existingSession.type, connectedEventName, + idToken: existingSession.user.idToken, }) .catch((e) => { console.warn("Failed to load user from session", e); diff --git a/account-kit/smart-contracts/package.json b/account-kit/smart-contracts/package.json index 6063dfecb7..410d8a66b2 100644 --- a/account-kit/smart-contracts/package.json +++ b/account-kit/smart-contracts/package.json @@ -35,7 +35,7 @@ "./package.json": "./package.json" }, "scripts": { - "generate": "npx tsx ../plugingen/src/cli.ts generate && yarn _lint:generated", + "generate": "npx tsx ../plugingen/src/cli.ts generate && yarn _lint:generated 1> /dev/null", "_lint:generated": "dotenv -e ../../.env -- eslint . --fix --config ../../.eslintrc --ignore-path ../../.prettierignore && prettier --write --ignore-path ../../.prettierignore .", "build": "yarn clean && yarn build:esm && yarn build:types", "build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm", diff --git a/examples/ui-demo/src/components/shared/mint-card/MintCard.tsx b/examples/ui-demo/src/components/shared/mint-card/MintCard.tsx index e2a63fbaaf..2173616122 100644 --- a/examples/ui-demo/src/components/shared/mint-card/MintCard.tsx +++ b/examples/ui-demo/src/components/shared/mint-card/MintCard.tsx @@ -61,7 +61,8 @@ export const MintCard = () => { }); setNFTTransfered(true); }; - const handleError = () => { + const handleError = (error: Error) => { + console.error(error); setStatus(initialValuePropState); setToast({ type: "error", diff --git a/turbo.json b/turbo.json index 134eb159f1..abe6139288 100644 --- a/turbo.json +++ b/turbo.json @@ -23,11 +23,6 @@ "docs:gen": { "dependsOn": ["ak-docgen#build"], "outputs": ["../../site/pages/reference/**"] - }, - "dev": { - "dependsOn": ["^build"], - "persistent": true, - "cache": false } } }