Installation & Setup
Getting started with Stack in 5 minutes
Setup
Welcome to the Next.js SDK setup guide. If you’re looking to set up Stack Auth with vanilla JavaScript instead, check out our JavaScript SDK Setup.
Before getting started, make sure you have a Next.js project using the app router, as Stack Auth does not support the pages router.
We recommend using our setup wizard for a seamless installation experience. The wizard automatically detects your project structure and walks you through the setup process. If you encounter any issues with the wizard, you can follow our manual installation steps instead.
Setup wizard (recommended)
Manual installation
Update API keys
Then, create an account on the Stack Auth dashboard, create a new project with an API key, and copy its environment variables into the .env.local
file of your Next.js project:
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 withStackProvider
andStackTheme
.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, likeuseUser
, are loading.stack.ts
: This file contains thestackServerApp
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 sign-up 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:
Next steps
Next up, we will show you how to retrieve and update user information, and how to protect a page.