diff --git a/docs/fern/docs/pages/sdk/account-settings.mdx b/docs/fern/docs/pages/sdk/account-settings.mdx new file mode 100644 index 0000000000..58559d2ae9 --- /dev/null +++ b/docs/fern/docs/pages/sdk/account-settings.mdx @@ -0,0 +1,27 @@ +--- +title: AccountSettings +--- + +# AccountSettings + +A component that renders account settings with various sections in a sidebar layout. It can be displayed as a full page or embedded. + +## Props + +- `fullPage` (optional): `boolean` - If true, wraps the component in a container for full-page display. Default is `false`. + +## Example + +```tsx +import { AccountSettings } from '@stackframe/stack'; + +// Embedded version +function MyComponent() { + return ; +} + +// Full-page version +function MyFullPageComponent() { + return ; +} +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/auth-page.mdx b/docs/fern/docs/pages/sdk/auth-page.mdx new file mode 100644 index 0000000000..9394e8e0d0 --- /dev/null +++ b/docs/fern/docs/pages/sdk/auth-page.mdx @@ -0,0 +1,35 @@ +--- +title: AuthPage +--- + +# AuthPage + +Renders an authentication page for sign-in or sign-up functionality. + +## Props + +- `fullPage` (optional): `boolean` - Whether to render the auth page in full-page mode. Defaults to `false`. +- `type`: `'sign-in' | 'sign-up'` - The type of authentication page to render. +- `automaticRedirect` (optional): `boolean` - Whether to automatically redirect after successful authentication. +- `mockProject` (optional): `object` - Mock project configuration for testing purposes. + - `config`: `object` + - `signUpEnabled`: `boolean` + - `credentialEnabled`: `boolean` + - `magicLinkEnabled`: `boolean` + - `oauthProviders`: `Array<{ id: string }>` + +## Example + +```tsx +import { AuthPage } from '@stackframe/stack'; + +// Sign-in page + + +// Sign-up page with full-page mode and automatic redirect + +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/credential-sign-in.mdx b/docs/fern/docs/pages/sdk/credential-sign-in.mdx new file mode 100644 index 0000000000..3603cb6370 --- /dev/null +++ b/docs/fern/docs/pages/sdk/credential-sign-in.mdx @@ -0,0 +1,26 @@ +--- +title: CredentialSignIn +--- + +# CredentialSignIn + +A React component that renders a sign-in form using email and password credentials. + +## Props + +This component does not accept any props. + +## Example + +```tsx +import { CredentialSignIn } from '@stackframe/stack'; + +function SignInPage() { + return ( +
+

Sign In

+ +
+ ); +} +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/credential-sign-up.mdx b/docs/fern/docs/pages/sdk/credential-sign-up.mdx new file mode 100644 index 0000000000..99e985010b --- /dev/null +++ b/docs/fern/docs/pages/sdk/credential-sign-up.mdx @@ -0,0 +1,28 @@ +--- +title: CredentialSignUp +--- + +# CredentialSignUp + +A React component that renders a sign-up form for credential-based authentication. + +## Props + +This component does not accept any props. + +## Example + +```tsx +import { CredentialSignUp } from '@stackframe/stack'; + +function SignUpPage() { + return ( +
+

Sign Up

+ +
+ ); +} +``` + +This component renders a form with email and password fields, handles form submission, and manages the sign-up process using the Stack SDK. \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/email-verification.mdx b/docs/fern/docs/pages/sdk/email-verification.mdx new file mode 100644 index 0000000000..b1c920a37e --- /dev/null +++ b/docs/fern/docs/pages/sdk/email-verification.mdx @@ -0,0 +1,31 @@ +--- +title: EmailVerification +--- + +# EmailVerification + +A component for handling email verification processes. It displays different messages based on the verification status. + +## Props + +- `searchParams` (optional): `Record` - An object containing search parameters. It should have a `code` property for the verification code. +- `fullPage` (optional): `boolean` - Determines if the component should be displayed in full-page mode. Default is `false`. + +## Example + +```tsx +import { EmailVerification } from '@stackframe/stack'; + +// Basic usage + + +// With search params and full-page mode + + +// Using with URL search params +const searchParams = new URLSearchParams(window.location.search); + +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/forgot-password.mdx b/docs/fern/docs/pages/sdk/forgot-password.mdx new file mode 100644 index 0000000000..24f1fa4baf --- /dev/null +++ b/docs/fern/docs/pages/sdk/forgot-password.mdx @@ -0,0 +1,23 @@ +--- +title: ForgotPassword +--- + +# ForgotPassword + +A component that renders a forgot password form or relevant messages based on the user's state. + +## Props + +- `fullPage` (optional): `boolean` - Determines if the component should be rendered in full-page mode. Default is `false`. + +## Example + +```tsx +import { ForgotPassword } from '@stackframe/stack'; + +// Default usage + + +// Full-page mode + +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/magic-link-sign-in.mdx b/docs/fern/docs/pages/sdk/magic-link-sign-in.mdx new file mode 100644 index 0000000000..ff0ae80237 --- /dev/null +++ b/docs/fern/docs/pages/sdk/magic-link-sign-in.mdx @@ -0,0 +1,28 @@ +--- +title: MagicLinkSignIn +--- + +# MagicLinkSignIn + +A React component that renders a form for magic link sign-in functionality. + +## Props + +This component does not accept any props. + +## Example + +```tsx +import { MagicLinkSignIn } from '@stackframe/stack'; + +function SignInPage() { + return ( +
+

Sign In

+ +
+ ); +} +``` + +The `MagicLinkSignIn` component renders a form with an email input and a submit button. When the form is submitted, it sends a magic link to the provided email address. \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/message-card.mdx b/docs/fern/docs/pages/sdk/message-card.mdx new file mode 100644 index 0000000000..8d7dc1e634 --- /dev/null +++ b/docs/fern/docs/pages/sdk/message-card.mdx @@ -0,0 +1,37 @@ +--- +title: MessageCard +--- + +# MessageCard + +Renders a message card component with optional buttons and full-page display. + +## Props + +- `title`: `string` - The title of the message card. +- `children` (optional): `React.ReactNode` - The content of the message card. +- `fullPage` (optional): `boolean` - Whether to display the card in full-page mode. Default is `false`. +- `primaryButtonText` (optional): `string` - Text for the primary button. +- `primaryAction` (optional): `() => Promise | void` - Function to execute when the primary button is clicked. +- `secondaryButtonText` (optional): `string` - Text for the secondary button. +- `secondaryAction` (optional): `() => Promise | void` - Function to execute when the secondary button is clicked. + +## Example + +```tsx +import { MessageCard } from '@stackframe/stack'; + +function ExampleMessage() { + return ( + console.log('Getting started')} + secondaryButtonText='Learn More' + secondaryAction={() => console.log('Learning more')} + > +

This is an example message card.

+
+ ); +} +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/oauth-button-group.mdx b/docs/fern/docs/pages/sdk/oauth-button-group.mdx new file mode 100644 index 0000000000..4883b54ab1 --- /dev/null +++ b/docs/fern/docs/pages/sdk/oauth-button-group.mdx @@ -0,0 +1,32 @@ +--- +title: OAuthButtonGroup +--- + +# OAuthButtonGroup + +Renders a group of OAuth buttons for sign-in or sign-up functionality. + +## Props + +- `type`: `'sign-in' | 'sign-up'` - Specifies whether the buttons are for sign-in or sign-up. +- `mockProject` (optional): `{ config: { oauthProviders: { id: string }[] } }` - Mocked project configuration for testing purposes. + +## Example + +```tsx +import { OAuthButtonGroup } from '@stackframe/stack'; + +// Basic usage + + +// With mock project +const mockProject = { + config: { + oauthProviders: [ + { id: 'google' }, + { id: 'github' } + ] + } +}; + +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/oauth-button.mdx b/docs/fern/docs/pages/sdk/oauth-button.mdx new file mode 100644 index 0000000000..d6cfc2d52d --- /dev/null +++ b/docs/fern/docs/pages/sdk/oauth-button.mdx @@ -0,0 +1,27 @@ +--- +title: OAuthButton +--- + +# OAuthButton + +A customizable OAuth button component for sign-in or sign-up functionality. + +## Props + +- `provider`: `string` - The OAuth provider (e.g., 'google', 'github', 'facebook', 'microsoft', 'spotify'). +- `type`: `'sign-in' | 'sign-up'` - The type of action, either 'sign-in' or 'sign-up'. + +## Example + +```tsx +import { OAuthButton } from '@stackframe/stack'; + +function SignInPage() { + return ( +
+ + +
+ ); +} +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/password-reset.mdx b/docs/fern/docs/pages/sdk/password-reset.mdx new file mode 100644 index 0000000000..682315f4bc --- /dev/null +++ b/docs/fern/docs/pages/sdk/password-reset.mdx @@ -0,0 +1,29 @@ +--- +title: PasswordReset +--- + +# PasswordReset + +A component for handling password reset functionality. It displays different messages based on the validity and state of the password reset code. + +## Props + +- `searchParams`: `Record` - An object containing search parameters, including the password reset code. +- `fullPage` (optional): `boolean` - Determines if the component should be displayed in full-page mode. Defaults to `false`. + +## Example + +```tsx +import { PasswordReset } from '@stackframe/stack'; + +function ResetPasswordPage() { + const searchParams = { code: 'reset123' }; + + return ( + + ); +} +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/selected-team-switcher.mdx b/docs/fern/docs/pages/sdk/selected-team-switcher.mdx new file mode 100644 index 0000000000..36f5d75e8f --- /dev/null +++ b/docs/fern/docs/pages/sdk/selected-team-switcher.mdx @@ -0,0 +1,29 @@ +--- +title: SelectedTeamSwitcher +--- + +# SelectedTeamSwitcher + +A component that allows users to switch between teams and manage team-related actions. + +## Props + +- `urlMap` (optional): A function that takes a `Team` object and returns a URL string for navigation. +- `selectedTeam` (optional): `Team` - The currently selected team. +- `noUpdateSelectedTeam` (optional): `boolean` - If true, prevents updating the selected team when a new team is chosen. + +## Example + +```tsx +import { SelectedTeamSwitcher } from '@stackframe/stack'; + +function TeamManagement() { + return ( + `/team/${team.id}`} + selectedTeam={currentTeam} + noUpdateSelectedTeam={false} + /> + ); +} +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/server-user.mdx b/docs/fern/docs/pages/sdk/server-user.mdx new file mode 100644 index 0000000000..ebd653b1a9 --- /dev/null +++ b/docs/fern/docs/pages/sdk/server-user.mdx @@ -0,0 +1,76 @@ +# ServerUser + +Represents a server-side user object with extended functionality and properties. + +## Properties + +- **`id`**: `string` + Unique identifier for the user. + +- **`displayName`**: `string` + User's display name. + +- **`primaryEmail`**: `string` + User's primary email address. + +- **`primaryEmailVerified`**: `boolean` + Indicates if the primary email is verified. + +- **`profileImageUrl`**: `string` + URL of the user's profile image. + +- **`signedUpAt`**: `Date` + Date when the user signed up. + +- **`clientMetadata`**: `any` + Custom metadata for client use. + +- **`clientReadOnlyMetadata`**: `any` + Read-only custom metadata for client use. + +- **`emailAuthEnabled`**: `boolean` + Indicates if email authentication is enabled. + +- **`hasPassword`**: `boolean` + Indicates if the user has set a password. + +- **`oauthProviders`**: `{ id: string }[]` + Array of connected OAuth providers. + +- **`isMultiFactorRequired`**: `boolean` + Indicates if multi-factor authentication is required. + +- **`selectedTeam`**: `Object` + Information about the user's selected team. + +## Methods + +ServerUser includes various methods for user management, team operations, and permission handling. Some key methods include: + +- **`setPrimaryEmail`** +- **`updatePassword`** +- **`setDisplayName`** +- **`sendVerificationEmail`** +- **`createTeam`** +- **`leaveTeam`** +- **`hasPermission`** +- **`grantPermission`** +- **`revokePermission`** + +## Example + +```tsx +import { ServerUser } from '@stackframe/stack'; + +// Assuming you have a ServerUser instance +const user: ServerUser = /* ... */; + +console.log(user.displayName); +console.log(user.primaryEmail); + +// Update user's display name +await user.setDisplayName('New Name'); + +// Check if user has a specific permission +const hasPermission = await user.hasPermission('read:documents'); +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/sign-in.mdx b/docs/fern/docs/pages/sdk/sign-in.mdx index ed3d315661..ab06cf28a9 100644 --- a/docs/fern/docs/pages/sdk/sign-in.mdx +++ b/docs/fern/docs/pages/sdk/sign-in.mdx @@ -1,14 +1,23 @@ --- -slug: sdk/sign-in +title: SignIn --- -The `SignIn` component is a pre-built UI element that displays all available sign-in methods as configured in the Stack dashboard. +# SignIn - - This component does not redirect a signed-in user. To achieve automatic redirection for signed-in users, you can use the `useUser` hook to check the user's sign-in status and perform the redirection if necessary. - - -![Sign In Component](../imgs/sign-in.png) +A component that renders a sign-in page using the AuthPage component. ## Props -- `fullPage` (boolean): Determines whether the component should occupy the full page. Default is `false`. \ No newline at end of file + +- `fullPage` (optional): `boolean` - Determines whether to display the sign-in page in full-page mode. Default is `false`. + +## Example + +```tsx +import { SignIn } from '@stackframe/stack'; + +// Default usage + + +// Full-page mode + +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/sign-up.mdx b/docs/fern/docs/pages/sdk/sign-up.mdx index f1b94df678..f1c4570f6f 100644 --- a/docs/fern/docs/pages/sdk/sign-up.mdx +++ b/docs/fern/docs/pages/sdk/sign-up.mdx @@ -1,14 +1,23 @@ --- -slug: sdk/sign-up +title: SignUp --- -The `SignUp` component is a pre-built component that displays all the sign up methods available based on the Stack dashboard configuration. +# SignUp - - This component does not redirect a signed-in user. To achieve automatic redirection for signed-in users, you can use the `useUser` hook to check the user's sign-in status and perform the redirection if necessary. - - -![Sign Up Component](../imgs/sign-up.png) +Renders a sign-up page component. Can be displayed as a full page or embedded within other content. ## Props -- `fullPage` (boolean): Determines whether the component should occupy the full page. Default is `false`. \ No newline at end of file + +- `fullPage` (optional): `boolean` - Determines whether to render the sign-up page in full-page mode. Defaults to `false`. + +## Example + +```tsx +import { SignUp } from '@stackframe/stack'; + +// Default usage (embedded) + + +// Full-page mode + +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/stack-handler.mdx b/docs/fern/docs/pages/sdk/stack-handler.mdx index 639b3af1a0..90c7fb025f 100644 --- a/docs/fern/docs/pages/sdk/stack-handler.mdx +++ b/docs/fern/docs/pages/sdk/stack-handler.mdx @@ -1,16 +1,37 @@ --- -slug: sdk/stack-handler +title: StackHandler --- -The `StackHandler` component is designed to manage navigation for all pages under the `/handler/*` route. It serves as a wrapper component that determines which page to display based on the URL path and configurations in the `StackApp`. +# StackHandler - - By default, this component will redirect users to appropriate pages. For example, if a user is not signed in and tries to access the account settings page, it will redirect the user to the sign-in page. - +A handler function for managing various authentication and user-related pages in a Stack application. ## Props -- `app` (StackServerApp): The component relies on the configurations from `app` to determine the correct page URLs and handle redirections. -- `params` (object): This should be passed down from the parent component to relay any URL parameters. -- `searchParams` (object): This should be passed down from the parent component to relay any search parameters from the URL. -- `fullPage` (boolean): Determines whether the component should occupy the full page. The default value is `false`. \ No newline at end of file +- `app`: `StackServerApp` - The Stack server application instance. +- `params` (optional): `{ stack?: string[] }` - URL parameters, where `stack` is an array of path segments. +- `searchParams` (optional): `Record` - Query parameters from the URL. +- `fullPage` (optional): `boolean` - Whether to render the component in full-page mode. Default is `false`. + +## Example + +```tsx +import StackHandler from '@stackframe/stack'; + +export default async function Page({ + params, + searchParams +}: { + params: { stack: string[] }, + searchParams: { [key: string]: string | string[] | undefined } +}) { + return ( + + ); +} +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/stack-provider.mdx b/docs/fern/docs/pages/sdk/stack-provider.mdx new file mode 100644 index 0000000000..4d7f460506 --- /dev/null +++ b/docs/fern/docs/pages/sdk/stack-provider.mdx @@ -0,0 +1,27 @@ +--- +title: StackProvider +--- + +# StackProvider + +A component that provides Stack authentication context to its children. + +## Props + +- `children`: `React.ReactNode` - The child components to be wrapped by the provider. +- `app`: `StackClientApp` - A Stack client app instance with authentication enabled. + +## Example + +```tsx +import { StackProvider } from '@stackframe/stack'; +import { app } from './stackApp'; + +function MyApp({ children }) { + return ( + + {children} + + ); +} +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/stack-server-app.mdx b/docs/fern/docs/pages/sdk/stack-server-app.mdx new file mode 100644 index 0000000000..61dfe0038a --- /dev/null +++ b/docs/fern/docs/pages/sdk/stack-server-app.mdx @@ -0,0 +1,56 @@ +# StackServerApp + +Type definition for the server-side application object in the Stack framework. + +## Props + +- **`createTeam`**: `(data: ServerTeamCreateOptions) => Promise` + Creates a new team. + +- **`getServerUser`**: `() => Promise | null>` + Deprecated. Use `getUser()` instead. + +- **`createUser`**: `(options: ServerUserCreateOptions) => Promise` + Creates a new user. + +- **`useUser`**: + - `(options: GetUserOptions & { or: 'redirect' }) => ProjectCurrentServerUser` + - `(options: GetUserOptions & { or: 'throw' }) => ProjectCurrentServerUser` + - `(options?: GetUserOptions) => ProjectCurrentServerUser | null` + +- **`getUser`**: + - `(options: GetUserOptions & { or: 'redirect' }) => Promise>` + - `(options: GetUserOptions & { or: 'throw' }) => Promise>` + - `(options?: GetUserOptions) => Promise | null>` + +- **`users`**: AsyncStoreProperty for managing users. + +- **`team`**: AsyncStoreProperty for managing a single team. + +- **`teams`**: AsyncStoreProperty for managing multiple teams. + +## Example + +```tsx +import { StackServerApp } from '@stackframe/stack'; + +const app: StackServerApp = { + async createTeam(data) { + // Implementation + }, + async getUser(options) { + // Implementation + }, + async createUser(options) { + // Implementation + }, + useUser(options) { + // Implementation + }, + // ... other properties and methods +}; + +// Using the app +const newTeam = await app.createTeam({ name: 'My Team' }); +const currentUser = await app.getUser(); +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/stack-theme.mdx b/docs/fern/docs/pages/sdk/stack-theme.mdx new file mode 100644 index 0000000000..bea920ad0c --- /dev/null +++ b/docs/fern/docs/pages/sdk/stack-theme.mdx @@ -0,0 +1,44 @@ +--- +title: StackTheme +--- + +# StackTheme + +A component to apply a custom theme to your Stack application. + +## Props + +- `theme` (optional): `ThemeConfig` - Custom theme configuration. + - `light`: Object containing light theme colors. + - `dark`: Object containing dark theme colors. + - `radius`: Custom border radius value. +- `children`: `React.ReactNode` - Child components to be wrapped by the theme. +- `nonce` (optional): `string` - A nonce for the inline script and style tags. + +## Example + +```tsx +import { StackTheme } from '@stackframe/stack'; + +function App() { + const customTheme = { + light: { + background: '#ffffff', + foreground: '#000000', + // ... other light theme colors + }, + dark: { + background: '#000000', + foreground: '#ffffff', + // ... other dark theme colors + }, + radius: '0.5rem', + }; + + return ( + + {/* Your app components */} + + ); +} +``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/use-stack-app.mdx b/docs/fern/docs/pages/sdk/use-stack-app.mdx index 19c9965186..d97eff5dd2 100644 --- a/docs/fern/docs/pages/sdk/use-stack-app.mdx +++ b/docs/fern/docs/pages/sdk/use-stack-app.mdx @@ -1,16 +1,42 @@ --- -slug: sdk/use-stack-app +title: useStackApp --- -The `useStackApp` hook returns the `StackClientApp` object that you can use to interact with the Stack API. If you want to learn more about the `StackClientApp` object, check out the [App](./stack-app.mdx) documentation. +# useStackApp -Example: +Returns the StackServerApp instance for the current project. Must be used within a StackProvider. -```jsx -import { useStackApp } from "@stackframe/stack"; +## Parameters + +- `options` (optional): An object with the following properties: + - `projectIdMustMatch` (optional): `ProjectId` - If provided, ensures the returned app matches this project ID. + +## Example + +```tsx +import { useStackApp, StackServerApp } from '@stackframe/stack'; + +// Initialize the StackServerApp +export const stackServerApp = new StackServerApp({ + tokenStore: "nextjs-cookie", +}); function MyComponent() { - const stackApp = useStackApp(); - return
Sign In URL: {stackApp.urls.signIn}
; + // Basic usage + const app = useStackApp(); + + // With project ID check + const app = useStackApp({ projectIdMustMatch: 'my-project-id' }); + + // Using the app + const user = app.auth.useUser(); + const project = app.projects.useProject(); + + // Redirect example + const handleSignOut = () => { + app.auth.signOut(); + }; + + // ... rest of your component } ``` \ No newline at end of file diff --git a/docs/fern/docs/pages/sdk/use-user.mdx b/docs/fern/docs/pages/sdk/use-user.mdx index f64d84cd3b..8a6ffaeafb 100644 --- a/docs/fern/docs/pages/sdk/use-user.mdx +++ b/docs/fern/docs/pages/sdk/use-user.mdx @@ -1,46 +1,45 @@ --- -slug: sdk/use-user +title: useUser --- -`useUser` is a hook that returns the user object if the user is authenticated; otherwise, it returns `null` by default. However, if you pass in `{ or: "redirect" }` or `{ or: "throw" }` as an option, it will redirect to the login page or throw an error respectively when the user is not authenticated. +# useUser -If you want to learn more about the `User` object, check out the [User](./current-user.mdx) documentation. +Retrieves the current user information based on the provided options. -## Default Usage +## Parameters -Check if the user is authenticated and display the user's name. -```jsx -import { useUser } from "@stackframe/stack"; +- `options` (optional): `GetUserOptions` - Configuration options for user retrieval. + - `or`: `'redirect' | 'throw' | 'return-null'` - Specifies behavior when user is not found. + - `tokenStore`: `'cookie' | 'nextjs-cookie' | 'memory' | { headers: { get: {} } } | { accessToken: string, refreshToken: string }` - Defines how to store authentication tokens. + - `projectIdMustMatch`: `string` - Ensures the project ID matches the specified value. -function MyComponent() { - const user = useUser(); // user can be null - if (!user) { - return
Not authenticated
; - } - return
Hello, {user.name}
; -} -``` +## Example -## Redirect when not authenticated -By passing `{ or: "redirect" }` to the hook, it will redirect to the login page if the user is not authenticated. You can configure the login page in the StackApp component. -```jsx -import { useUser } from "@stackframe/stack"; +```tsx +import { useUser } from '@stackframe/stack'; -function MyComponent() { - const user = useUser({ or: "redirect" }); // user is garanteed to be non-null - return
Hello, {user.name}
; -} -``` +// Basic usage +const user = useUser(); -The same hook can also be used to protect a page. (You might also want to check out the server-side version [here](../getting-started/users.mdx)) -```jsx -import { useUser } from "@stackframe/stack"; +// With options +const internalUser = useUser({ + or: 'throw', + tokenStore: 'cookie', + projectIdMustMatch: 'internal' +}); + +// Accessing user properties +if (user) { + console.log(user.displayName); + console.log(user.primaryEmail); +} -function MyProtectedPage() { - useUser({ or: "redirect" }); - return
You can only see this if you are authenticated
; +// Using user methods +if (internalUser) { + await internalUser.setDisplayName('New Name'); + const team = await internalUser.createTeam({ name: 'New Team' }); } -``` +`````` ## Throw an error when not authenticated diff --git a/docs/fern/docs/pages/sdk/user-button.mdx b/docs/fern/docs/pages/sdk/user-button.mdx new file mode 100644 index 0000000000..86ec464ccc --- /dev/null +++ b/docs/fern/docs/pages/sdk/user-button.mdx @@ -0,0 +1,35 @@ +--- +title: UserButton +--- + +# UserButton + +Renders a user button component with customizable options. + +## Props + +- `showUserInfo`: `boolean` - Determines whether to display user information. +- `colorModeToggle`: `object` - Configuration for the color mode toggle. +- `extraItems`: `Array<{ text: string, icon: React.ReactNode, onClick: Function }>` - Additional items to be displayed in the user menu. + +## Example + +```tsx +import { UserButton } from '@stackframe/stack'; + +function MyComponent() { + return ( + , + onClick: () => console.log('Settings clicked') + } + ]} + /> + ); +} +``` \ No newline at end of file