Skip to content

Commit

Permalink
made onloginsuccess callback only fire onlogin
Browse files Browse the repository at this point in the history
  • Loading branch information
jmderby committed Feb 15, 2025
1 parent 45dec65 commit 42af24f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ export function CrossmintAuthProvider({
setDialogOpen(false);

// FOR STANDALONE AUTH ONLY! EXCLUDING PASSKEY HELPERS.
// Skip if passkey helpers are enabled because they have to still create a wallet.
if (onLoginSuccess != null && !(embeddedWallets.showPasskeyHelpers ?? true)) {
// not for existing sessions or page refreshes.
// Skip for passkey-enabled flows as they handle success separately.
if (dialogOpen && onLoginSuccess != null && !(embeddedWallets.showPasskeyHelpers ?? true)) {
onLoginSuccess();
}
}, [crossmint.jwt, onLoginSuccess, embeddedWallets.showPasskeyHelpers]);
}, [crossmint.jwt, dialogOpen, onLoginSuccess, embeddedWallets.showPasskeyHelpers]);

const login = () => {
if (crossmint.jwt != null) {
Expand Down Expand Up @@ -180,6 +181,7 @@ export function CrossmintAuthProvider({
showPasskeyHelpers={embeddedWallets.showPasskeyHelpers}
appearance={appearance}
onLoginSuccess={onLoginSuccess}
dialogOpen={dialogOpen}
>
<AuthFormProvider
preFetchOAuthUrls={getAuthStatus() === "logged-out"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ export function CrossmintWalletProvider({
showPasskeyHelpers = true,
appearance,
onLoginSuccess,
dialogOpen,
}: {
children: ReactNode;
defaultChain: EVMSmartWalletChain;
showPasskeyHelpers?: boolean;
appearance?: UIConfig;
onLoginSuccess?: () => void;
dialogOpen: boolean;
}) {
const { crossmint } = useCrossmint("CrossmintWalletProvider must be used within CrossmintProvider");
const smartWalletSDK = useMemo(() => SmartWalletSDK.init({ clientApiKey: crossmint.apiKey }), [crossmint.apiKey]);
Expand Down Expand Up @@ -95,7 +97,8 @@ export function CrossmintWalletProvider({
setWalletState({ status: "loaded", wallet });

// Upon getting/creating a wallet, trigger the onLoginSuccess callback
if (onLoginSuccess != null) {
// Only fire if the dialog is open
if (onLoginSuccess != null && dialogOpen) {
onLoginSuccess();
}
} catch (error: unknown) {
Expand Down

0 comments on commit 42af24f

Please sign in to comment.