stack/docs/templates/components/user-button.mdx
Madison bc2b7a1c4e
[Docs][site] - Add signin functionality (#876)
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md
-->

Adds signin with Stack Auth, allowing users to sign into our docs.
Features to come with this later down the line.

<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Add Stack Auth user authentication and UI enhancements with
`UserButton` and updated import paths.
> 
>   - **Features**:
> - Added `UserButton` for user authentication in `home-layout.tsx`,
`shared-header.tsx`, and `stack-user-button-demo.tsx`.
> - Introduced `Handler` component in `page.tsx` to integrate
`stackServerApp` with `StackHandler`.
>     - Added `Loading` component in `loading.tsx` for loading screen.
>   - **Imports**:
>     - Updated `stackServerApp` import path in `layout.tsx`.
>   - **UI Enhancements**:
> - Updated navbar layout in `home-layout.tsx` to include `UserButton`
and improved social links.
> - Enhanced `UserButtonDemo` to use real account data when signed in.
>   - **Configuration**:
> - Configured `stackServerApp` in `stack.ts` with environment variables
for authentication.
>   - **Documentation**:
> - Updated `user-button.mdx` to reflect changes in `UserButton`
component.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for 4aeed316f7. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>

----


<!-- ELLIPSIS_HIDDEN -->

<!-- RECURSEML_SUMMARY:START -->
## Review by RecurseML

_🔍 Review performed on
[faf79e5..2659adc](faf79e5a9e...2659adc22a)_

 No bugs found, your code is sparkling clean

<details>
<summary> Files analyzed, no issues (5)</summary>

  • `docs/src/components/stack-auth/stack-user-button-demo.tsx`
  • `docs/src/components/layouts/home-layout.tsx`
  • `docs/src/components/layouts/shared-header.tsx`
  • `docs/src/app/loading.tsx`
  • `docs/src/app/handler/[...stack]/page.tsx`
</details>

<details>
<summary>⏭️ Files skipped (low suspicion) (4)</summary>

  • `docs/src/app/global.css`
  • `docs/src/app/layout.tsx`
  • `docs/src/stack.ts`
  • `docs/templates/components/user-button.mdx`
</details>

[![Need help? Join our
Discord](https://img.shields.io/badge/Need%20help%3F%20Join%20our%20Discord-5865F2?style=plastic&logo=discord&logoColor=white)](https://discord.gg/n3SsVDAW6U)
<!-- RECURSEML_SUMMARY:END -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- New Features
- Added an account UserButton to desktop and mobile headers; refined
navbar layout and branding.
  - Introduced a full-page handler route.
  - Added a global loading screen.
- UserButton demo now uses your signed-in account when available, with
clear status; falls back to mock data otherwise.

- Documentation
- Updated component docs to reference UserButton (replacing previous
naming).
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
2025-09-10 01:32:10 -05:00

80 lines
1.9 KiB
Plaintext

---
title: "<UserButton />"
---
The `<UserButton>` renders a user button component with optional user information, color mode toggle, and extra menu items.
## Interactive Demo
Try out the UserButton component with different props and see the changes in real-time:
<UserButtonDemo />
## Props
<PropTable
props={[
{
name: "showUserInfo",
type: "boolean",
description: "If true, displays user information (display name and email) in the button.",
optional: true,
default: "false"
},
{
name: "colorModeToggle",
type: "() => void | Promise<void>",
description: "Function to be called when the color mode toggle button is clicked. If specified, a color mode toggle button will be shown.",
optional: true,
default: "undefined"
},
{
name: "extraItems",
type: "Array",
description: "Additional menu items to display. Each item should have the following properties:",
optional: true,
nested: [
{
name: "text",
type: "string",
description: "The text to display for the item."
},
{
name: "icon",
type: "React.ReactNode",
description: "The icon to display for the item."
},
{
name: "onClick",
type: "() => void | Promise<void>",
description: "Function to be called when the item is clicked."
}
]
}
]}
/>
## Example
```tsx
'use client';
import { UserButton } from '@stackframe/stack';
export default function Page() {
return (
<div>
<h1>User Button</h1>
<UserButton
showUserInfo={true}
colorModeToggle={() => { console.log("color mode toggle clicked") }}
extraItems={[{
text: 'Custom Action',
icon: <CustomIcon />,
onClick: () => console.log('Custom action clicked')
}]}
/>
</div>
);
}
```