A modern, production-ready starter template for building secure web applications with Next.js App Router, Stack Auth authentication, and beautiful Shadcn UI components.
- Next.js 15 with App Router and Turbopack for blazing-fast development
- Stack Auth for secure, production-ready authentication
- Email/password authentication
- OAuth providers support
- User management dashboard
- Session handling with secure cookies
- Shadcn UI - A complete collection of accessible, customizable UI components
- TypeScript for type-safe development
- Tailwind CSS 4 for modern styling
- Biome for fast linting and formatting
- React Hook Form + Zod for form validation
- Lucide Icons for beautiful iconography
Before you begin, ensure you have the following installed:
- Node.js 20.x or later
- npm, yarn, pnpm, or bun package manager
- A Stack Auth account (free to create at stack-auth.com)
npm install
Or use your preferred package manager:
yarn install
# or
pnpm install
# or
bun install
- Go to stack-auth.com
- Sign up for a free account
- Create a new project
- Navigate to your project settings
In your Stack Auth dashboard:
- Go to Settings or API Keys
- Copy the following three values:
Project ID
Publishable Client Key
Secret Server Key
Create a .env.local
file in the root of your project:
cp .env.example .env.local
Open .env.local
and add your Stack Auth credentials:
# Stack Auth Configuration
NEXT_PUBLIC_STACK_PROJECT_ID=your_project_id_here
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=your_publishable_key_here
STACK_SECRET_SERVER_KEY=your_secret_key_here
Important: Never commit your .env.local
file to version control. It's already included in .gitignore
.
npm run dev
Or with your preferred package manager:
yarn dev
# or
pnpm dev
# or
bun dev
Open http://localhost:3000 in your browser to see your application.
nextjs-stack-auth/
├── src/
│ ├── app/
│ │ ├── handler/
│ │ │ └── [...stack]/ # Stack Auth route handlers
│ │ ├── layout.tsx # Root layout with Stack provider
│ │ ├── page.tsx # Home page with auth logic
│ │ └── loading.tsx # Loading states
│ ├── components/
│ │ ├── ui/ # Shadcn UI components
│ │ ├── AuthenticatedView.tsx # Content shown to logged-in users
│ │ └── UnauthenticatedView.tsx # Content shown to guests
│ ├── stack/
│ │ ├── client.tsx # Stack Auth client configuration
│ │ └── server.tsx # Stack Auth server configuration
│ ├── lib/
│ │ └── utils.ts # Utility functions (cn, etc.)
│ └── hooks/
│ └── use-mobile.ts # Mobile detection hook
├── .env.example # Example environment variables
├── .env.local # Your local environment variables (create this)
├── package.json
├── tailwind.config.ts
└── tsconfig.json
The template includes two main view components that you can customize:
Edit src/components/AuthenticatedView.tsx to customize what authenticated users see:
'use client';
import type { User } from "@stackframe/stack";
interface AuthenticatedViewProps {
user: User;
}
export function AuthenticatedView({ user }: AuthenticatedViewProps) {
return (
<div className="container mx-auto p-8">
<h1>Welcome back, {user.displayName || user.primaryEmail}!</h1>
{/* Add your authenticated content here */}
</div>
);
}
The user
object provides access to:
user.id
- Unique user identifieruser.displayName
- User's display nameuser.primaryEmail
- User's email addressuser.profileImageUrl
- User's profile picture URL- And more - see Stack Auth documentation
Edit src/components/UnauthenticatedView.tsx to customize the landing page for guests:
'use client';
export function UnauthenticatedView() {
return (
<div className="container mx-auto p-8">
<h1>Welcome to Our App</h1>
<p>Please sign in to continue</p>
{/* Add your landing page content here */}
</div>
);
}
This template includes a comprehensive set of Shadcn UI components. To use them in your components:
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
export function MyComponent() {
return (
<Card>
<Input placeholder="Enter text" />
<Button>Submit</Button>
</Card>
);
}
To add additional Shadcn components, visit ui.shadcn.com and follow their installation instructions.
Use Stack Auth hooks to access user data and authentication state:
'use client';
import { useUser, useStackApp } from "@stackframe/stack";
export function MyComponent() {
const user = useUser(); // Returns user object or null
const stackApp = useStackApp();
const handleSignOut = async () => {
await stackApp.signOut();
};
if (!user) {
return <div>Not signed in</div>;
}
return (
<div>
<p>Email: {user.primaryEmail}</p>
<button onClick={handleSignOut}>Sign Out</button>
</div>
);
}
npm run dev # Start development server with Turbopack
npm run build # Build for production
npm run start # Start production server
npm run lint # Run Biome linter
npm run format # Format code with Biome
Stack Auth provides pre-built authentication UI components:
- Sign in page
- Sign up page
- Password reset
- Email verification
- User profile settings
- Account settings
Access these at: http://localhost:3000/handler/sign-in
Configure Stack Auth in src/stack/client.tsx:
import { StackClientApp } from "@stackframe/stack";
export const stackClientApp = new StackClientApp({
tokenStore: "nextjs-cookie",
// Add more configuration options here
});
For server components and API routes, use Stack Auth server configuration from src/stack/server.tsx.
The easiest way to deploy your Next.js app is with Vercel:
- Push your code to GitHub, GitLab, or Bitbucket
- Import your repository to Vercel
- Add your environment variables in the Vercel dashboard:
NEXT_PUBLIC_STACK_PROJECT_ID
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY
STACK_SECRET_SERVER_KEY
- Deploy!
For other platforms, build with npm run build
and deploy the .next
folder.
- Environment Variables: Ensure all environment variables are set in your deployment platform
- Stack Auth Configuration: Update your Stack Auth project settings with your production domain
- Callback URLs: Add your production URLs to Stack Auth's allowed callback URLs
- Verify all three environment variables are set correctly in
.env.local
- Ensure you've restarted the development server after adding environment variables
- Check that your Stack Auth project is active and not in development mode
- Double-check that you copied the correct keys from Stack Auth
- Ensure there are no extra spaces or quotes in your
.env.local
file - Verify you're using the keys from the correct Stack Auth project
- Run
npm install
to ensure all dependencies are installed - Clear Next.js cache:
rm -rf .next
- Restart your development server
- Ensure Tailwind CSS is properly configured
- Check that you've imported the component correctly
- Verify your
globals.css
file includes Tailwind directives
- Next.js Documentation - Learn about Next.js features and API
- Stack Auth Documentation - Complete Stack Auth guide
- Shadcn UI Documentation - UI component documentation
- Tailwind CSS Documentation - Tailwind CSS reference
This is an open-source template. Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
- Improve documentation
This template is open source and available under the MIT License.
If you encounter issues:
- Check the Troubleshooting section
- Review the documentation links above
- Open an issue on GitHub
- Join the Stack Auth Discord community
Happy coding! If you found this template helpful, please consider giving it a star.