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

fix links referencing multi-session feature; update userbutton component reference #2010

Merged
merged 6 commits into from
Feb 12, 2025
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
10 changes: 10 additions & 0 deletions docs/authentication/configuration/session-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ To enable multi-session in your application, you need to configure it in the Cle
1. Toggle on **Multi-session handling**.
1. Select **Save**.

### Add multi-session support to your app

<If sdk={['nextjs', 'react']}>
It's highly recommended to wrap your application in the [`<MultisessionAppSupport />`](/docs/components/control/multi-session) component. This guarantees a full rerendering cycle every time the current session and user changes.
</If>

<If sdk={["nextjs", "react", "expo", "react-router", "tanstack-start"]}>
You can pass the `afterMultiSessionSingleSignOutUrl` property to [`<ClerkProvider>`](/docs/components/clerk-provider) to specify where to navigate to after signing out from a currently active account in a multi-session app.
</If>

There are two main ways to add the multi-session feature to your application:

- Use the [`<UserButton />`](/docs/components/user/user-button) component if you want to use a prebuilt UI.
Expand Down
9 changes: 4 additions & 5 deletions docs/components/clerk-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ The recommended approach is to wrap your entire app with `<ClerkProvider>` at th
<Tab>
```tsx {{ filename: 'index.tsx' }}
import React from 'react'
import ReactDOM from 'react-dom'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import { ClerkProvider } from '@clerk/clerk-react'
import App from './App'

// Import your Publishable Key
const PUBLISHABLE_KEY = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
Expand All @@ -58,13 +58,12 @@ The recommended approach is to wrap your entire app with `<ClerkProvider>` at th
throw new Error('Add your Clerk Publishable Key to the .env.local file')
}

ReactDOM.render(
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ClerkProvider publishableKey={PUBLISHABLE_KEY}>
<ClerkProvider publishableKey={PUBLISHABLE_KEY} afterSignOutUrl="/">
<App />
</ClerkProvider>
</React.StrictMode>,
document.getElementById('root'),
)
```
</Tab>
Expand Down
73 changes: 45 additions & 28 deletions docs/components/control/multi-session.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,49 @@ The `<MultisessionAppSupport>` provides a wrapper for your React application tha

<Tabs items={["Next.js", "React"]}>
<Tab>
```tsx {{ filename: 'pages/_app.tsx' }}
import '@/styles/globals.css'
import { MultisessionAppSupport, ClerkProvider } from '@clerk/nextjs/internal'
import { AppProps } from 'next/app'

function MyApp({ Component, pageProps }: AppProps) {
return (
<ClerkProvider {...pageProps}>
<MultisessionAppSupport>
<Component {...pageProps} />
</MultisessionAppSupport>
</ClerkProvider>
)
}
<CodeBlockTabs options={["App Router", "Pages Router"]}>
```tsx {{ filename: 'app/layout.tsx' }}
import React from 'react'
import { ClerkProvider, MultisessionAppSupport } from '@clerk/nextjs'

export default MyApp
```
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<ClerkProvider>
<MultisessionAppSupport>
<body>{children}</body>
</MultisessionAppSupport>
</ClerkProvider>
</html>
)
}
```

```tsx {{ filename: 'pages/_app.tsx' }}
import { ClerkProvider, MultisessionAppSupport } from '@clerk/nextjs'
import type { AppProps } from 'next/app'

function MyApp({ Component, pageProps }: AppProps) {
return (
<ClerkProvider {...pageProps}>
<MultisessionAppSupport>
<Component {...pageProps} />
</MultisessionAppSupport>
</ClerkProvider>
)
}

export default MyApp
```
</CodeBlockTabs>
</Tab>

<Tab>
```tsx {{ filename: 'app.tsx' }}
import { ClerkProvider, MultisessionAppSupport } from '@clerk/clerk-react/internal'
```tsx {{ filename: 'index.tsx' }}
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import { ClerkProvider, MultisessionAppSupport } from '@clerk/clerk-react'

// Import your Publishable Key
const PUBLISHABLE_KEY = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
Expand All @@ -39,19 +60,15 @@ The `<MultisessionAppSupport>` provides a wrapper for your React application tha
throw new Error('Add your Clerk Publishable Key to the .env.local file')
}

function App() {
return (
<ClerkProvider publishableKey={PUBLISHABLE_KEY}>
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ClerkProvider publishableKey={PUBLISHABLE_KEY} afterSignOutUrl="/">
<MultisessionAppSupport>
<Page />
<App />
</MultisessionAppSupport>
</ClerkProvider>
)
}

function Page() {
return <div>The content</div>
}
</React.StrictMode>,
)
```
</Tab>
</Tabs>
Loading
Loading