A modern, full-stack boilerplate for building web applications with Bluesky OAuth authentication using Next.js, Prisma, and PostgreSQL.
- π Bluesky OAuth Authentication - Secure authentication using AT Protocol OAuth
- ποΈ PostgreSQL Database - Robust database with Prisma ORM
- πͺ Persistent Sessions - Session management with iron-session
- β‘ Bun Runtime - Fast package management and development with Bun
- π¨ Modern UI - Built with Tailwind CSS and custom components
- π§ TypeScript - Full type safety throughout the application
- π¦ Prisma Models - Pre-configured models for auth states and sessions
- Framework: Next.js 15 with App Router
- Runtime: Bun
- Database: PostgreSQL with Prisma ORM
- Authentication: AT Protocol OAuth (@atproto/oauth-client-node)
- Session Management: iron-session
- Styling: Tailwind CSS
- Language: TypeScript
- Code Quality: Biome (ESLint + Prettier alternative)
- Bun installed on your machine
- PostgreSQL database
- Environment variables configured
git clone https://github.com/pirmax/bluesky-oauth-nextjs
cd bluesky-oauth-nextjs
bun install
Create a .env.local
file in the root directory:
# Database
POSTGRES_URL="postgresql://username:password@localhost:5432/your_database"
# App Configuration
NEXT_PUBLIC_URL="http://localhost:3000"
# Session Security
COOKIE_PASSWORD="your-32-characters-secret-key-here"
You can generate 32 caracters on 1password.com.
# Generate Prisma client
bunx prisma generate
# Run database migrations
bunx prisma migrate dev
bun dev
Open http://localhost:3000 to see your application.
src/
βββ app/ # Next.js App Router
β βββ oauth/ # OAuth authentication routes
β β βββ login/ # Login page
β β βββ callback/ # OAuth callback handler
β βββ private/ # Protected pages
β βββ client-metadata.json/ # OAuth client metadata
βββ components/ # Reusable UI components
β βββ bluesky-logo.tsx
β βββ login-button.tsx
β βββ logout-button.tsx
βββ functions/ # Business logic
β βββ create-user.ts # User creation utilities
βββ lib/ # Core utilities
β βββ actions.ts # Server actions
β βββ atproto.ts # AT Protocol client setup
β βββ iron.ts # Session management
β βββ prisma.ts # Database client
β βββ storage.ts # Storage implementations
βββ styles/
βββ globals.css # Global styles
The boilerplate includes two main Prisma models:
Stores OAuth state parameters for security:
model AuthState {
key String @id
state String
}
Stores OAuth session data:
model AuthSession {
key String @id
session String
}
- Login: User clicks login button and is redirected to Bluesky OAuth
- Authorization: User authorizes the application on Bluesky
- Callback: Bluesky redirects back with authorization code
- Token Exchange: Application exchanges code for access tokens
- Profile Fetch: Application fetches user profile from Bluesky
- Session Creation: User data is stored in iron-session cookie
# Development
bun dev # Start development server with Turbopack
# Production
bun run build # Build for production
bun start # Start production server
# Code Quality
bun run lint # Run Biome linter
bun run format # Format code with Biome
# Database
bunx prisma generate # Generate Prisma client
bunx prisma migrate dev # Run database migrations
bunx prisma studio # Open Prisma Studio
Variable | Description | Required |
---|---|---|
POSTGRES_URL |
PostgreSQL connection string | β |
NEXT_PUBLIC_URL |
Your application's public URL | β |
COOKIE_PASSWORD |
32-character secret for session encryption | β |
- Connect your repository to Vercel
- Add environment variables in Vercel dashboard
- Set up PostgreSQL database (Vercel Postgres or external)
- Deploy
- Build the application:
bun run build
- Set up PostgreSQL database
- Run migrations:
bunx prisma migrate deploy
- Start the server:
bun start
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature
- Commit your changes:
git commit -m 'Add new feature'
- Push to the branch:
git push origin feature/new-feature
- Open a pull request
This project is open source and available under the MIT License.
For support and questions:
- Open an issue on GitHub
- Check the AT Protocol documentation
- Review the Next.js documentation