Getting Started
Get BastionAuth running in under 10 minutes.
Prerequisites
- Node.js 20+
- pnpm 8+
- Docker & Docker Compose
Quick Start
1. Get Your License Key
First, sign up at bastionauth.dev (opens in a new tab) to get your FREE license key.
2. Install
# For Next.js projects
npm install @bastionauth/nextjs
# For React projects
npm install @bastionauth/react
# For custom integrations
npm install @bastionauth/core2. Start Infrastructure
# Start PostgreSQL and Redis
pnpm docker:up
# Generate Prisma client
pnpm db:generate
# Run migrations
pnpm db:migrate3. Configure Environment
cp env.example .envEdit .env with your configuration:
# Server
NODE_ENV=development
PORT=3001
API_URL=http://localhost:3001
APP_URL=http://localhost:3000
# Database
DATABASE_URL=postgresql://bastionauth:bastionauth@localhost:5432/bastionauth
# Redis
REDIS_URL=redis://localhost:6379
# Email (Resend)
RESEND_API_KEY=re_your_api_key
FROM_EMAIL=noreply@yourdomain.com4. Generate Security Keys
./scripts/generate-keys.shThis creates RS256 key pair for JWT signing.
5. Start Development
pnpm devThis starts:
- API Server: http://localhost:3001 (opens in a new tab)
- Example App: http://localhost:3000 (opens in a new tab)
- Admin Dashboard: http://localhost:3003 (opens in a new tab)
Your First Integration
React App
import { BastionProvider, SignIn, useAuth } from '@bastionauth/react';
function App() {
return (
<BastionProvider
publishableKey="pk_live_..."
apiUrl="http://localhost:3001"
>
<MyApp />
</BastionProvider>
);
}
function MyApp() {
const { isSignedIn, user } = useAuth();
if (!isSignedIn) {
return <SignIn />;
}
return <div>Welcome, {user.email}!</div>;
}Next.js App
// middleware.ts
import { authMiddleware } from '@bastionauth/nextjs';
export default authMiddleware({
publicRoutes: ['/', '/sign-in', '/sign-up'],
});
export const config = {
matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
};// app/dashboard/page.tsx
import { auth, currentUser } from '@bastionauth/nextjs/server';
export default async function Dashboard() {
const { userId } = await auth();
const user = await currentUser();
return <h1>Hello, {user?.firstName}!</h1>;
}