> ## Documentation Index
> Fetch the complete documentation index at: https://stytch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

> How to install and set up the Stytch B2B Frontend SDK in your application.

For a full walk-through of how to get up and running with a sign-up and login flow using Stytch, including page router instructions, check out our [Quickstart Guide](https://stytch.com/docs/get-started/quickstart.md).
The instructions below assume you are using app router.

**1. Install Packages**

Install the Next.js package:

```bash theme={null}
npm install @stytch/nextjs
```

**2. Create a Stytch context component**

Create a new StytchContext client component.
Initialize the Stytch client, passing in your Project's `public_token` from the [Project Overview](https://stytch.com/dashboard) of the Stytch Dashboard.
Pass the Stytch client to the `<StytchB2BProvider>` component.

```jsx StytchContext.jsx theme={null}
'use client';

import { createStytchB2BClient, StytchB2BProvider } from '@stytch/nextjs/b2b';

const stytch = createStytchB2BClient(
  process.env.NEXT_PUBLIC_STYTCH_PUBLIC_TOKEN, // or process.env.STYTCH_PUBLIC_TOKEN for non-Vite based projects
);

export const StytchContext = ({ children }) => (
  <StytchB2BProvider stytch={stytch}>
    {children}
  </StytchB2BProvider>
);
```

**3. Wrap your application in \<StytchB2BProvider>**

Next, pass the Stytch client to the `<StytchB2BProvider>` component at the root of your application, making it accessible to all child components.

```jsx layout.jsx theme={null}
import { StytchContext } from './StytchContext';

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <StytchContext>{children}</StytchContext>
      </body>
    </html>
  );
}
```

**4. Add your login flow**

You have now initialized the Stytch client, and can add the `<StytchB2B>` [pre-built login component](https://stytch.com/docs/api-reference/b2b/frontend-sdks/nextjs/prebuilt-ui/login/configuration.md) to get a robust, end-to-end login flow working with just a simple config.
