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: Added custom button component for the SignInButton component #170

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
49 changes: 37 additions & 12 deletions packages/auth-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,45 @@ export const SignIn = ({ nonce }: { nonce: string }) => {
};
```

#### Customizing the `SignInButton` button component

```tsx
import { SignInButton } from "@farcaster/auth-kit";

export const SignIn = ({ nonce }: { nonce: string }) => {
return (
<SignInButton
nonce={nonce}
onSuccess={({ fid, username }) =>
console.log(`Hello, ${username}! Your fid is ${fid}.`)
}

Button={({ onClick }) => (
<button onClick={onClick}>
My custom sign in with farcaster button.
Only prop to ensure is onClick
</button>
)}
/>
);
};
```

#### Props

| Prop | Type | Required | Description | Default |
| ------------------ | ----------------------------------- | -------- | ----------------------------------------------------------------------------------- | -------------------- |
| `timeout` | `number` | No | Relay server timeout in ms. | `300000` (5 minutes) |
| `interval` | `number` | No | Relay server polling interval in ms. | `1500` (1.5 seconds) |
| `nonce` | `string` | No | Random nonce to include in the Sign In With Farcaster message. | None |
| `notBefore` | `string` | No | Time when the SIWF message becomes valid. ISO 8601 datetime string. | None |
| `expirationTime` | `string` | No | Time when the SIWF message expires. ISO 8601 datetime string. | None |
| `requestId` | `string` | No | An optional system specific ID to include in the SIWF message. | None |
| `onSuccess` | `(res: UseSignInData) => void` | No | Callback invoked when sign in is complete and the user is authenticated. | None |
| `onStatusResponse` | `(res: UseWatchStatusData) => void` | No | Callback invoked when the component receives a status update from the relay server. | None |
| `onError` | `(error: AuthClientError) => void` | No | Error callback function. | None |
| `debug` | `boolean` | No | Render a debug panel displaying internal AuthKit state. | `false` |
| Prop | Type | Required | Description | Default |
| ------------------ | ------------------------------------------ | -------- | ----------------------------------------------------------------------------------- | -------------------- |
| `Button` | `({ onClick: () => void }) => JSX.Element` | No | Pass in custom button component
| `timeout` | `number` | No | Relay server timeout in ms. | `300000` (5 minutes) |
| `interval` | `number` | No | Relay server polling interval in ms. | `1500` (1.5 seconds) |
| `nonce` | `string` | No | Random nonce to include in the Sign In With Farcaster message. | None |
| `notBefore` | `string` | No | Time when the SIWF message becomes valid. ISO 8601 datetime string. | None |
| `expirationTime` | `string` | No | Time when the SIWF message expires. ISO 8601 datetime string. | None |
| `requestId` | `string` | No | An optional system specific ID to include in the SIWF message. | None |
| `onSuccess` | `(res: UseSignInData) => void` | No | Callback invoked when sign in is complete and the user is authenticated. | None |
| `onStatusResponse` | `(res: UseWatchStatusData) => void` | No | Callback invoked when the component receives a status update from the relay server. | None |
| `onError` | `(error: AuthClientError) => void` | No | Error callback function. | None |
| `debug` | `boolean` | No | Render a debug panel displaying internal AuthKit state. | `false` |

## Hooks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ type SignInButtonProps = UseSignInArgs & {
onSignOut?: () => void;
debug?: boolean;
hideSignOut?: boolean;
Button?: (props: { onClick: () => void }) => JSX.Element;
};

export function SignInButton({
debug,
hideSignOut,
onSignOut,
Button,
...signInArgs
}: SignInButtonProps) {
const { onSuccess, onStatusResponse, onError } = signInArgs;
Expand Down Expand Up @@ -103,7 +105,10 @@ export function SignInButton({
/>
) : (
<>
<ActionButton onClick={onClick} label="Sign in" />
{ Button
? <Button onClick={onClick} />
: <ActionButton onClick={onClick} label="Sign in" />
}
{url && (
<QRCodeDialog
open={showDialog && !isMobile()}
Expand Down