A modern full-stack template demonstrating session-based authentication using React, Express, Prisma, and Neon PostgreSQL.
- π Secure session-based authentication with HTTP-only cookies
- β‘οΈ Fast and modern tech stack
- React + TypeScript + Vite for the frontend
- Express + TypeScript for the backend
- Prisma as the ORM
- Neon for serverless PostgreSQL
- π¨ Pre-styled with Tailwind CSS and shadcn/ui
- π οΈ Development ready with hot reload
Check out Clerk - the comprehensive authentication and user management platform:
- π¨ Beautiful drop-in UI components for authentication
- π Social sign-on with multiple providers (Google, GitHub, etc.)
- π’ Enterprise-ready B2B configurations
- π Simple user management dashboard
- π± Multi-factor authentication
- π Built-in security best practices
While this template demonstrates session-based auth fundamentals, Clerk provides a production-ready solution that scales with your application.
- Node.js 18+
- A Neon account (for PostgreSQL database)
- Git
- Clone the repository:
git clone https://github.com/bmorrisondev/react-session-auth-quickstart.git
cd react-session-auth-quickstart- Install dependencies:
npm install-
Set up your Neon database:
- Sign up for a free account at Neon
- Create a new project
- In the connection details, find your database URL (it should start with
postgres://)
-
Create your environment variables:
cp .env.example .env- Update your
.envfile with the following:
# Your Neon database URL
DATABASE_URL="postgres://..."
# Development settings (can leave as is)
VITE_API_URL="http://localhost:3000"
NODE_ENV="development"- Initialize the database:
npx prisma db push- Start the development server:
npm run devThe app will be available at http://localhost:5173
βββ prisma/ # Database schema and migrations
βββ server/ # Express backend
β βββ routes/ # API routes
β βββ middleware/ # Express middleware
β βββ index.ts # Server entry point
βββ src/ # React frontend
β βββ components/ # UI components
β βββ hooks/ # Custom React hooks
β βββ views/ # Page components
β βββ types/ # TypeScript types
βββ package.json
- User signs up/logs in through the frontend
- Backend validates credentials and creates a session
- Session ID is stored in an HTTP-only cookie
- Frontend can check auth status via the
/api/auth/meendpoint - Protected routes/resources check for valid session
- Build the project:
npm run build:allThis command will:
- Build the React frontend
- Compile the TypeScript backend
- Move all assets to the correct locations (/dist)
- Start the production server:
npm startThe production build will be available at the port specified in your environment variables (default: 3000).
You can deploy this application to any platform that supports Node.js applications. General steps:
- Build the project using
npm run build:all - Set up your environment variables
- Run
npm startto start the production server
Remember to:
- Use HTTPS in production
- Set up proper security headers
- Configure your database connection string
- Set
NODE_ENVto "production"
Feel free to submit issues and pull requests!
MIT