Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 26 additions & 16 deletions site/pages/react/login-methods/email-magic-link.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,22 @@ import { useAuthenticate } from "@account-kit/react";
const { authenticate } = useAuthenticate();

// When the user submits their email
const handleSendMagicLink = async (email: string) => {
try {
await authenticate({
const handleSendMagicLink = (email: string) => {
authenticate(
{
type: "email",
emailMode: "magicLink",
email,
});
// Success - inform user to check their email
} catch (error) {
// Handle error
}
},
{
onSuccess: () => {
// Success - inform user to check their email
},
onError: (error) => {
// Handle error
},
}
);
};
```

Expand All @@ -131,20 +136,25 @@ const { authenticate } = useAuthenticate();

// Handle the redirect when the component mounts
useEffect(() => {
const handleRedirect = async () => {
const handleRedirect = () => {
const url = new URL(window.location.href);
const bundle = url.searchParams.get("bundle");

if (bundle) {
try {
await authenticate({
authenticate(
{
type: "email",
bundle,
});
// Authentication successful!
} catch (error) {
// Handle error
}
},
{
onSuccess: () => {
// Authentication successful!
},
onError: (error) => {
// Handle error
},
}
);
}
};

Expand Down
42 changes: 26 additions & 16 deletions site/pages/react/login-methods/email-otp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,22 @@ import { useAuthenticate } from "@account-kit/react";
const { authenticate } = useAuthenticate();

// When the user submits their email
const handleSendCode = async (email: string) => {
try {
await authenticate({
const handleSendCode = (email: string) => {
authenticate(
{
type: "email",
emailMode: "otp",
email,
});
// Success - now show the OTP input form
} catch (error) {
// Handle error
}
},
{
onSuccess: () => {
// Success - now show the OTP input form
},
onError: (error) => {
// Handle error
},
}
);
};
```

Expand All @@ -127,16 +132,21 @@ import { useAuthenticate } from "@account-kit/react";
const { authenticate } = useAuthenticate();

// When the user submits the OTP code
const handleVerifyCode = async (otpCode: string) => {
try {
await authenticate({
const handleVerifyCode = (otpCode: string) => {
authenticate(
{
type: "otp",
otpCode,
});
// Authentication successful!
} catch (error) {
// Handle invalid code error
}
},
{
onSuccess: () => {
// Authentication successful!
},
onError: (error) => {
// Handle invalid code error
},
}
);
};
```

Expand Down
42 changes: 26 additions & 16 deletions site/pages/react/login-methods/passkey-login.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,21 @@ import { useAuthenticate } from "@account-kit/react";
const { authenticate } = useAuthenticate();

// When the user wants to log in with their passkey and email
const handlePasskeyLogin = async (email: string) => {
try {
await authenticate({
const handlePasskeyLogin = (email: string) => {
authenticate(
{
type: "passkey",
email,
});
// Success - user authenticated with passkey
} catch (error) {
// Handle error
}
},
{
onSuccess: () => {
// Success - user authenticated with passkey
},
onError: (error) => {
// Handle error
},
}
);
};
```

Expand All @@ -113,16 +118,21 @@ import { useAuthenticate } from "@account-kit/react";
const { authenticate } = useAuthenticate();

// When the user wants to log in with just their passkey
const handlePasskeyOnlyLogin = async () => {
try {
await authenticate({
const handlePasskeyOnlyLogin = () => {
authenticate(
{
type: "passkey",
createNew: false, // Important: set to false to prevent creating a new passkey
});
// Success - user authenticated with passkey
} catch (error) {
// Handle error
}
},
{
onSuccess: () => {
// Success - user authenticated with passkey
},
onError: (error) => {
// Handle error
},
}
);
};
```

Expand Down
51 changes: 31 additions & 20 deletions site/pages/react/login-methods/passkey-signup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,27 @@ import { useAuthenticate } from "@account-kit/react";
const { authenticate } = useAuthenticate();

// When the user submits their email and wants to create a passkey
const handlePasskeySignup = async (email: string) => {
try {
// Important: Validate the email before proceeding
if (!isValidEmail(email)) {
throw new Error("Please enter a valid email address");
}
const handlePasskeySignup = (email: string) => {
// Important: Validate the email before proceeding
if (!isValidEmail(email)) {
// Handle validation error
return;
}

await authenticate({
authenticate(
{
type: "passkey",
email,
});
// Success - passkey created and user authenticated
} catch (error) {
// Handle error
}
},
{
onSuccess: () => {
// Success - passkey created and user authenticated
},
onError: (error) => {
// Handle error
},
}
);
};

// Simple email validation function
Expand All @@ -132,17 +138,22 @@ import { useAuthenticate } from "@account-kit/react";
const { authenticate } = useAuthenticate();

// When the user wants to create a passkey without email
const handlePasskeyOnlySignup = async (username: string) => {
try {
await authenticate({
const handlePasskeyOnlySignup = (username: string) => {
authenticate(
{
type: "passkey",
createNew: true,
username, // A unique identifier for the passkey
});
// Success - passkey created and user authenticated
} catch (error) {
// Handle error
}
},
{
onSuccess: () => {
// Success - passkey created and user authenticated
},
onError: (error) => {
// Handle error
},
}
);
};
```

Expand Down
40 changes: 24 additions & 16 deletions site/pages/react/login-methods/social-login.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,40 @@ import { useAuthenticate } from "@account-kit/react";
const { authenticate, isPending } = useAuthenticate();

// For redirect flow
const handleGoogleRedirectLogin = async () => {
try {
await authenticate({
const handleGoogleRedirectLogin = () => {
authenticate(
{
type: "oauth",
authProviderId: "google",
mode: "redirect",
redirectUrl: "/", // Redirect to this page after authentication
});
// The page will redirect, so no need for success handling here
} catch (error) {
// Handle error
}
},
{
onError: (error) => {
// Handle error
// The page will redirect on success, so no need for onSuccess handler
},
}
);
};

// For popup flow
const handleGooglePopupLogin = async () => {
try {
await authenticate({
const handleGooglePopupLogin = () => {
authenticate(
{
type: "oauth",
authProviderId: "google",
mode: "popup",
});
// Authentication successful!
} catch (error) {
// Handle error
}
},
{
onSuccess: () => {
// Authentication successful!
},
onError: (error) => {
// Handle error
},
}
);
};
```

Expand Down
42 changes: 26 additions & 16 deletions site/pages/react/login-methods/social-providers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,32 +171,42 @@ import { useAuthenticate } from "@account-kit/react";
const { authenticate } = useAuthenticate();

// Option 1: Generic Auth0 login (shows Auth0 provider selection screen)
const handleAuth0Login = async () => {
try {
await authenticate({
const handleAuth0Login = () => {
authenticate(
{
type: "oauth",
authProviderId: "auth0",
mode: "popup", // or "redirect"
});
// Authentication successful!
} catch (error) {
// Handle error
}
},
{
onSuccess: () => {
// Authentication successful!
},
onError: (error) => {
// Handle error
},
}
);
};

// Option 2: Direct provider login (bypasses Auth0 selection screen)
const handleGitHubLogin = async () => {
try {
await authenticate({
const handleGitHubLogin = () => {
authenticate(
{
type: "oauth",
authProviderId: "auth0",
auth0Connection: "github", // Use the connection name from Auth0
mode: "popup", // or "redirect"
});
// Authentication successful!
} catch (error) {
// Handle error
}
},
{
onSuccess: () => {
// Authentication successful!
},
onError: (error) => {
// Handle error
},
}
);
};
```

Expand Down
2 changes: 1 addition & 1 deletion site/pages/react/react-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import React from "react";
import { useAuthenticate } from "@account-kit/react";

function MyAuthComponent() {
const { authenticate, isPending } = useAuthenticate();
const { authenticate, authenticateAsync, isPending } = useAuthenticate();

// Use authenticate with different parameters based on auth method
// The specific parameters depend on the authentication method
Expand Down