There are two branches you can use: main: Business Coupon System for business to issue coupons and player to redeem coupons and write off it. It will be updated frequently.
basic: Initial version of the business coupon system, it is a basic authentication system, you can use it as a basic authentication system to develop your own application.
nextauth:Basic Authentication System using NextAuthjs, you can use it as a basic authentication system to develop your own application.
A central application for managing coupons between merchants and players. Will add more features to this system.
- Node.js 18+ and pnpm
- PostgreSQL database
- Google OAuth credentials (https://console.cloud.google.com/apis/credentials)
- Google Maps API key (https://console.cloud.google.com/google/maps-apis/credentials)
- Clone the repository:
git clone <repository-url>
cd basic-central-app
- Install dependencies:
pnpm install
- Set up environment variables:
cp .env.example .env
Edit .env
file with your configurations:
DATABASE_URL
: Your PostgreSQL connection stringAUTH_GOOGLE_ID
andAUTH_GOOGLE_SECRET
: Google OAuth credentialsNEXT_PUBLIC_GOOGLE_MAPS_KEY
: Google Maps API keyAUTH_SECRET
: Random string for session encryption
- Set up the database:
# Push the database schema
npx prisma db push
# Generate Prisma Client
npx prisma generate
- Initialize coupon categories:
npx tsx data/seed-categories.ts
- Configure Google Maps API:
- Go to Google Cloud Console
- Navigate to your project
- Go to "APIs & Services" > "Credentials"
- Find your Maps API key
- Under "Application restrictions", set "HTTP referrers (websites)"
- Add the following URLs:
http://localhost:3000/* http://localhost/*
- Start the development server:
pnpm dev
After starting the server:
-
Sign in with your Google account
-
Choose your role:
- Register as a merchant to create and manage coupons
- Register as a player to browse and redeem coupons
-
For merchants:
- Use recharge codes to get points for publishing coupons
- Create coupon templates with various promotion types
- Monitor coupon usage and points balance
-
For players:
- Browse available coupons from different merchants
- Use points to purchase coupons
- View purchased coupons and their QR codes/passcodes
The following scripts are available for development:
- Recharge merchant points:
npx tsx data/recharge-merchants.ts
- Recharge player points:
npx tsx data/recharge-players.ts
- List users and their profiles:
npx tsx data/list-users.ts
- List all coupons and their status:
npx tsx data/list-coupons.ts
/app
: Next.js app router pages and layouts/components
: Reusable React components/lib
: Utility functions and shared code/prisma
: Database schema and migrations/public
: Static assets/data
: Development tools and scripts
- Create and manage coupon templates
- Monitor coupon usage and redemption
- Track points balance and transactions
- View customer engagement metrics
- Browse available coupons
- Purchase coupons with points
- View purchased coupons
- Access QR codes and passcodes
-
Database Issues:
- Ensure PostgreSQL is running
- Check DATABASE_URL in .env
- Run
npx prisma db push
to sync schema - For local development, you can use:
postgresql://postgres:postgres@localhost:5432/your_db_name
-
Authentication Issues:
- Get credentials from https://console.cloud.google.com/apis/credentials
- Set up OAuth 2.0 Client ID with these redirect URIs:
http://localhost:3000/auth/callback/google http://localhost:3000/auth/signin
- Check AUTH_SECRET in .env (can be generated with
openssl rand -base64 32
) - Ensure redirect URIs are configured
-
Maps Issues:
- Get API key from https://console.cloud.google.com/google/maps-apis/credentials
- Enable these APIs in your project:
- Maps JavaScript API
- Places API
- Geocoding API
- Set up API key restrictions in Google Cloud Console
- Ensure key has required permissions