Skip to content
/ sunx Public template

Sunx a modern, production-ready authentication template built with Next.js , Better Auth, Prisma ORM, and shadcn/ui components.

License

Notifications You must be signed in to change notification settings

rajofearth/sunx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Sunx - Next.js Authentication Template

A modern, production-ready authentication template built with Next.js 15, Better Auth, Prisma ORM, and shadcn/ui components.

Sign In Page Sign Up Page Dashboard
## ✨ Features
  • πŸ” Complete Authentication Flow - Sign up, sign in, password reset
  • 🎨 Modern UI - Beautiful dark theme with glassmorphism effects
  • ⚑ Next.js 15 - Latest App Router with server actions
  • πŸ—„οΈ Database Ready - SQLite with Prisma (easy to swap to PostgreSQL)
  • πŸ”’ Better Auth - Secure authentication with session management
  • πŸ“± Responsive Design - Works perfectly on all devices
  • 🎯 TypeScript - Full type safety throughout
  • 🎨 shadcn/ui - Professional UI components
  • πŸ”„ Server Actions - Form handling with Zod validation

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • bun, yarn, or pnpm

1. Clone and Install

git clone https://github.com/rajofearth/sunx.git
cd sunx
bun install

2. Environment Setup

cp .env.example .env

Update .env with your configuration:

# Database (SQLite by default)
DATABASE_URL="file:./local.db"

# App URL (no trailing slash)
NEXT_PUBLIC_APP_URL="http://localhost:3000"

3. Database Setup

# Generate Prisma client
bun run prisma:generate

# Push schema to database
bun run db:push

4. Start Development

bun dev

Open http://localhost:3000 in your browser.

πŸ—οΈ Project Structure

src/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”œβ”€β”€ page.tsx              # Auth page (protected from logged-in users)
β”‚   β”‚   └── action.ts             # Server actions for auth
β”‚   β”œβ”€β”€ dashboard/
β”‚   β”‚   └── page.tsx              # Protected dashboard
β”‚   β”œβ”€β”€ forgot-password/
β”‚   β”‚   └── page.tsx              # Password reset request
β”‚   β”œβ”€β”€ reset-password/
β”‚   β”‚   └── page.tsx              # Password reset form
β”‚   β”œβ”€β”€ api/auth/[...all]/
β”‚   β”‚   └── route.ts              # Better Auth API routes
β”‚   β”œβ”€β”€ globals.css               # Global styles & Tailwind
β”‚   β”œβ”€β”€ layout.tsx                # Root layout
β”‚   └── page.tsx                  # Home page (redirects to auth/dashboard)
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ auth-client.tsx           # Auth UI with tabs
β”‚   β”œβ”€β”€ sign-in.tsx               # Sign in form
β”‚   β”œβ”€β”€ sign-up.tsx               # Sign up form
β”‚   β”œβ”€β”€ forgot-password-client.tsx # Forgot password UI
β”‚   β”œβ”€β”€ reset-password-client.tsx # Reset password UI
β”‚   └── ui/                       # shadcn/ui components
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ auth.ts                   # Better Auth configuration
β”‚   β”œβ”€β”€ auth-client.ts            # Client-side auth utilities
β”‚   β”œβ”€β”€ action-helpers.ts         # Server action utilities
β”‚   β”œβ”€β”€ types.ts                  # Zod schemas
β”‚   β”œβ”€β”€ prisma.ts                 # Prisma client
β”‚   └── utils.ts                  # Utility functions
└── generated/
    └── prisma/                   # Generated Prisma client

πŸ”§ Configuration

Better Auth Setup

The authentication is configured in src/lib/auth.ts:

export const auth = betterAuth({
  emailAndPassword: {
    enabled: true,
    minPasswordLength: 8,
    maxPasswordLength: 128,
    async sendResetPassword({ user, url, token }, request) {
      // TODO: Implement your email sending logic here
      console.log(`Password reset email for ${user.email}: ${url}`);
    },
  },
  database: prismaAdapter(prisma, {
    provider: "sqlite",
  }),
  session: {
    expiresIn: 60 * 60 * 24 * 7, // 7 days
  },
  plugins: [nextCookies()],
});

Database Schema

The Prisma schema includes all necessary tables for Better Auth:

  • User - User information and authentication data
  • Session - User sessions for authentication
  • Account - OAuth and credential accounts
  • Verification - Email verification tokens

🎨 Customization

Styling

The template uses Tailwind CSS v4 with a custom dark theme. Customize by modifying:

  • src/app/globals.css - Global styles and CSS variables
  • Component-specific classes in the components
  • The theme uses CSS variables for easy customization

Email Provider

To enable email functionality (password reset, verification), implement the email sending functions in src/lib/auth.ts:

async sendResetPassword({ user, url, token }, request) {
  // Example with Resend
  await fetch('https://api.resend.com/emails', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.RESEND_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      from: '[email protected]',
      to: user.email,
      subject: 'Reset your password',
      html: `<a href="${url}">Reset Password</a>`,
    }),
  });
}

Popular email providers:

πŸš€ Deployment

Environment Variables

Set these in your production environment:

DATABASE_URL="your-production-database-url"
NEXT_PUBLIC_APP_URL="https://your-domain.com"

Database Migration

For production, consider using PostgreSQL:

  1. Update prisma/schema.prisma:
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
  1. Update the auth configuration:
database: prismaAdapter(prisma, {
  provider: "postgresql",
}),
  1. Deploy your database and run migrations:
npx prisma migrate deploy

Deployment Platforms

This template works with all major deployment platforms:

  • Vercel - Recommended for Next.js apps
  • Netlify - Great for static sites
  • Railway - Easy database + app deployment
  • Render - Simple deployment with PostgreSQL
  • AWS/GCP/Azure - Enterprise deployments

πŸ› οΈ Development

Available Scripts

bun dev          # Start development server
bun run build        # Build for production
bun run start        # Start production server
bun run typecheck    # TypeScript type checking
bun run prisma:generate  # Generate Prisma client
bun run db:push      # Push schema to database

Adding New Features

  1. New Pages: Add to src/app/ following the existing pattern
  2. Components: Create in src/components/ with proper TypeScript
  3. Server Actions: Use the validatedAction helper in src/lib/action-helpers.ts
  4. Database: Add models to prisma/schema.prisma

πŸ”’ Security Features

  • Password Hashing - Uses scrypt for secure password hashing
  • Session Management - Secure session handling with expiration
  • Input Validation - Zod schemas for all form inputs
  • CSRF Protection - Built-in CSRF protection with Better Auth
  • Rate Limiting - Configurable rate limiting for auth endpoints
  • Type Safety - Full TypeScript coverage

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments


Ready to build something amazing? πŸš€

This template provides a solid foundation for any Next.js application requiring authentication. Just add your business logic and deploy!

About

Sunx a modern, production-ready authentication template built with Next.js , Better Auth, Prisma ORM, and shadcn/ui components.

Topics

Resources

License

Stars

Watchers

Forks