Skip to content

Commit

Permalink
Auth: add onLoginSuccess callback
Browse files Browse the repository at this point in the history
  • Loading branch information
jmderby committed Feb 15, 2025
1 parent e4dc971 commit 72edf6c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type CrossmintAuthProviderProps = {
embeddedWallets?: CrossmintAuthWalletConfig;
appearance?: UIConfig;
termsOfServiceText?: string | ReactNode;
onLoginSuccess?: () => void;
authModalTitle?: string;
children: ReactNode;
loginMethods?: LoginMethod[];
Expand Down Expand Up @@ -67,6 +68,7 @@ export function CrossmintAuthProvider({
appearance,
termsOfServiceText,
authModalTitle,
onLoginSuccess,
loginMethods = ["email", "google"],
refreshRoute,
logoutRoute,
Expand Down Expand Up @@ -115,7 +117,13 @@ export function CrossmintAuthProvider({
}

setDialogOpen(false);
}, [crossmint.jwt]);

// 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)) {
onLoginSuccess();
}
}, [crossmint.jwt, onLoginSuccess, embeddedWallets.showPasskeyHelpers]);

const login = () => {
if (crossmint.jwt != null) {
Expand Down Expand Up @@ -171,6 +179,7 @@ export function CrossmintAuthProvider({
defaultChain={embeddedWallets.defaultChain}
showPasskeyHelpers={embeddedWallets.showPasskeyHelpers}
appearance={appearance}
onLoginSuccess={onLoginSuccess}
>
<AuthFormProvider
preFetchOAuthUrls={getAuthStatus() === "logged-out"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ export type WalletConfig = WalletParams & { type: "evm-smart-wallet" };
export function CrossmintWalletProvider({
children,
defaultChain,
showPasskeyHelpers = true, // enabled by default
showPasskeyHelpers = true,
appearance,
onLoginSuccess,
}: {
children: ReactNode;
defaultChain: EVMSmartWalletChain;
showPasskeyHelpers?: boolean;
appearance?: UIConfig;
onLoginSuccess?: () => void;
}) {
const { crossmint } = useCrossmint("CrossmintWalletProvider must be used within CrossmintProvider");
const smartWalletSDK = useMemo(() => SmartWalletSDK.init({ clientApiKey: crossmint.apiKey }), [crossmint.apiKey]);
Expand Down Expand Up @@ -91,6 +93,11 @@ export function CrossmintWalletProvider({
enhanceConfigWithPasskeyPrompts(config)
);
setWalletState({ status: "loaded", wallet });

// Upon getting/creating a wallet, trigger the onLoginSuccess callback
if (onLoginSuccess != null) {
onLoginSuccess();
}
} catch (error: unknown) {
console.error("There was an error creating a wallet ", error);
setWalletState(deriveErrorState(error));
Expand Down

0 comments on commit 72edf6c

Please sign in to comment.