Getting Started

Installation & Setup

Getting started with Stack in 5 minutes

Setup

To get started with Stack, you need a Next.js project with the app router. The pages router is not supported.

We recommend using our setup wizard, which will automatically detect your project structure and guide you through the installation process. In case it fails, you can choose to do the manual installation instead.

Run installation wizard

Run Stack’s installation wizard with the following command:

Terminal
1npx @stackframe/init-stack@latest

Update API keys

Then, you must create an account on our dashboard, create a new project with an API key, and copy its environment variables into the .env.local file of your Next.js project:

.env.local
1NEXT_PUBLIC_STACK_PROJECT_ID=<your-project-id>
2NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=<your-publishable-client-key>
3STACK_SECRET_SERVER_KEY=<your-secret-server-key>

Done!

That’s it! The following files should have been created or updated in your project:

  • app/handler/[...stack]/page.tsx: This file contains the default pages for sign-in, sign-out, account settings, and more. If you prefer, later you will learn how to use custom pages instead.
  • app/layout.tsx: The layout file was updated to wrap the entire body with StackProvider and StackTheme.
  • app/loading.tsx: If not yet found, Stack automatically adds a Suspense boundary to your app. This is shown to the user while Stack’s async hooks, like useUser, are loading.
  • stack.ts: This file contains the stackServerApp which you can use to access Stack from Server Components, Server Actions, API routes, and middleware.

Post-setup

That’s it! Stack is now configured in your Next.js project. If you start your Next.js app with npm run dev and navigate to http://localhost:3000/handler/signup, you will see the Stack sign-up page.

Stack sign in page

After signing up/in, you will be redirected back to the home page. We will show you how to add user information to it in the next section. You can also check out the http://localhost:3000/handler/account-settings page which looks like this:

Stack account settings page

Next steps

Next up, we will show you how to retrieve and update user information, and how to protect a page.