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

feat: oauth add passkey after signup (popup flow) #1151

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3882dca
chore: local dev changes updated
linnall Oct 30, 2024
8ab130a
Merge branch 'main' into social-auth-dev
linnall Oct 31, 2024
ca9e5fd
chore: merge in main
linnall Nov 1, 2024
0a63891
chore: wip oauth redirect with add passkey after signup
linnall Nov 4, 2024
f62b9c8
Merge branch 'main' into social-auth-dev
linnall Nov 5, 2024
8b42698
Merge branch 'main' into social-auth-dev
linnall Nov 8, 2024
bf02b3c
chore: wip
linnall Nov 8, 2024
5d5951a
refactor: remove a few things so we can test redirect
moldy530 Nov 8, 2024
ee46248
refactor: just render the pop-up on completed login for oauth
moldy530 Nov 8, 2024
13b1156
refactor: add new user signup event in signer
moldy530 Nov 8, 2024
1101154
refactor: add hook to listen to signup events
moldy530 Nov 8, 2024
c3aa3bf
chore: wip
linnall Nov 8, 2024
a559ab7
refactor: use signup event to popup passkey create
moldy530 Nov 8, 2024
f4a9d94
fix: the modal was staying open
moldy530 Nov 8, 2024
9b504a3
fix: move setAuthStep in the correct card
moldy530 Nov 8, 2024
0b592c0
fix: infinite subscribe loop
moldy530 Nov 8, 2024
d2c862c
fix: don't open passkey create until logged in
moldy530 Nov 8, 2024
979442b
Merge branch 'main' into social-auth-dev
linnall Nov 8, 2024
998463e
chore: remove local dev callback url
linnall Nov 8, 2024
1e04872
Merge branch 'main' into linna/oauth-add-passkey
linnall Nov 11, 2024
85edb03
chore: removes unecessary bangs and refactors for readability
linnall Nov 11, 2024
a853832
chore: removes unused usePrevious hook
linnall Nov 12, 2024
195149e
Merge branch 'main' into linna/oauth-add-passkey
linnall Nov 12, 2024
f061538
Merge branch 'main' into linna/oauth-add-passkey
linnall Nov 12, 2024
6060220
fix: update useNewUserSignup to remove listener on dismount and when …
linnall Nov 12, 2024
c0e796a
docs: link related discussion to TODO
linnall Nov 12, 2024
e1dda2f
refactor: adds emitNewUserEvent wrapper
linnall Nov 12, 2024
8d10d70
chore: restore oauth mode to popup
linnall Nov 12, 2024
46f694e
Merge branch 'main' into linna/oauth-add-passkey
linnall Nov 12, 2024
78e37ed
chore: remove logging
linnall Nov 13, 2024
1975bdd
chore: remove logging
linnall Nov 13, 2024
d952810
chore: reset oauth mode to popup
linnall Nov 13, 2024
640a7de
fix: handle undefined isNewUser within emitNewUserEvent wrapper
linnall Nov 13, 2024
1adcbd7
chore: remove unnecessary bang
linnall Nov 13, 2024
49309d8
Merge branch 'main' into linna/oauth-add-passkey
linnall Nov 13, 2024
6b17b45
Merge branch 'main' into linna/oauth-add-passkey-popup
linnall Nov 13, 2024
c1f44c6
Merge branch 'main' into linna/oauth-add-passkey-popup
linnall Nov 13, 2024
d72fa1a
feat: sets up event for client to emit to trigger signer to emit new …
linnall Nov 13, 2024
ac8dc20
Merge branch 'main' into linna/oauth-add-passkey-popup
linnall Nov 13, 2024
f7f650b
Merge branch 'main' into linna/oauth-add-passkey-popup
linnall Nov 14, 2024
995a210
chore: adds logging
linnall Nov 14, 2024
aa12a59
fix: solve the race condition on new user signup
moldy530 Nov 14, 2024
529fe0a
refactor: changes newUserSignupClient to newUserSignup
linnall Nov 14, 2024
0364404
Merge branch 'main' into linna/oauth-add-passkey-popup
linnall Nov 14, 2024
e7a76d3
chore: remove console trace
linnall Nov 14, 2024
e3467ba
chore: remove empty line
linnall Nov 14, 2024
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { OauthCancelledError } from "@account-kit/signer";
import { useEffect } from "react";
import { useSignerStatus } from "../../../../hooks/useSignerStatus.js";
import { ContinueWithOAuth } from "../../../../icons/oauth.js";
import { capitalize } from "../../../../utils.js";
import { useAuthContext } from "../../context.js";
import { useOAuthVerify } from "../../hooks/useOAuthVerify.js";
import { ConnectionError } from "../error/connection-error.js";
import { OauthCancelledError } from "@account-kit/signer";

export const CompletingOAuth = () => {
const { isConnected } = useSignerStatus();
Expand All @@ -15,11 +15,7 @@ export const CompletingOAuth = () => {

useEffect(() => {
if (isConnected) {
if (authStep.createPasskeyAfter) {
setAuthStep({ type: "passkey_create" });
} else {
setAuthStep({ type: "complete" });
}
setAuthStep({ type: "complete" });
} else if (oauthWasCancelled) {
setAuthStep({ type: "initial" });
}
Expand Down
11 changes: 6 additions & 5 deletions account-kit/react/src/components/auth/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback } from "react";
import { useNewUserSignup } from "../../hooks/internal/useNewUserSignup.js";
import { useAuthModal } from "../../hooks/useAuthModal.js";
import { useSignerStatus } from "../../hooks/useSignerStatus.js";
import { useUiConfig } from "../../hooks/useUiConfig.js";
import { useSignerStatus } from "../../index.js";
import { Dialog } from "../dialog/dialog.js";
import { AuthCardContent } from "./card/index.js";
import { useAuthContext } from "./context.js";
Expand All @@ -16,19 +16,20 @@ export const AuthModal = () => {
})
);

const { setAuthStep } = useAuthContext();
const { setAuthStep, authStep } = useAuthContext();
const { isOpen, closeAuthModal, openAuthModal } = useAuthModal();

const handleSignup = useCallback(() => {
if (addPasskeyOnSignup && !isOpen) {
if (addPasskeyOnSignup) {
openAuthModal();

setAuthStep({
type: "passkey_create",
});
}
}, [addPasskeyOnSignup, isOpen, openAuthModal, setAuthStep]);
}, [addPasskeyOnSignup, openAuthModal, setAuthStep]);

useNewUserSignup(handleSignup, isConnected);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this solves a race condition where an on success handler would set the step to complete and close the modal that was just opened. This makes sure that all handlers complete we're done with the setup flow prior to add passkey

useNewUserSignup(handleSignup, isConnected && authStep.type === "complete");

return (
<Dialog isOpen={isOpen} onClose={closeAuthModal}>
Expand Down
5 changes: 4 additions & 1 deletion account-kit/react/src/hooks/useAuthModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const useAuthModal = () => {
);

const openAuthModal = useCallback(() => setModalOpen(true), [setModalOpen]);
const closeAuthModal = useCallback(() => setModalOpen(false), [setModalOpen]);
const closeAuthModal = useCallback(() => {
console.trace("closing modal");
linnall marked this conversation as resolved.
Show resolved Hide resolved
setModalOpen(false);
}, [setModalOpen]);

return {
isOpen,
Expand Down
5 changes: 5 additions & 0 deletions account-kit/signer/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,11 @@ export abstract class BaseAlchemySigner<TClient extends BaseSignerClient>
}
})();

// trigger new user event on signer from client
this.inner.on("newUserSignupClient", () => {
this.emitNewUserEvent(true);
});

this.store.setState({
status,
error: null,
Expand Down
12 changes: 10 additions & 2 deletions account-kit/signer/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -19,7 +20,6 @@ import type {
OauthParams,
User,
} from "./types.js";
import { OAuthProvidersError } from "../errors.js";

const CHECK_CLOSE_INTERVAL = 500;

Expand Down Expand Up @@ -462,6 +462,7 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
"_blank",
"popup,width=500,height=600"
);
const eventEmitter = this.eventEmitter;
return new Promise((resolve, reject) => {
const handleMessage = (event: MessageEvent) => {
if (!event.data) {
Expand All @@ -471,6 +472,7 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
alchemyBundle: bundle,
alchemyOrgId: orgId,
alchemyIdToken: idToken,
alchemyIsSignup: isSignup,
alchemyError,
} = event.data;
if (bundle && orgId && idToken) {
Expand All @@ -482,7 +484,13 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
connectedEventName: "connectedOauth",
idToken,
authenticatingType: "oauth",
}).then(resolve, reject);
}).then((user) => {
if (isSignup) {
eventEmitter.emit("newUserSignupClient");
}

resolve(user);
}, reject);
} else if (alchemyError) {
cleanup();
popup?.close();
Expand Down
1 change: 1 addition & 0 deletions account-kit/signer/src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export type AuthenticatingEventMetadata = {

export type AlchemySignerClientEvents = {
connected(user: User): void;
newUserSignupClient(): void;
linnall marked this conversation as resolved.
Show resolved Hide resolved
authenticating(data: AuthenticatingEventMetadata): void;
connectedEmail(user: User, bundle: string): void;
connectedPasskey(user: User): void;
Expand Down
Loading