Backend server for the Driftype typing game, handling user authentication, password management, and game statistics.
- User registration and login
- Google Sign-In integration
- Password reset functionality with email notifications
- Game statistics tracking
- JWT-based authentication
- PostgreSQL database with Supabase but you can also use your postgreSQL local database
- Node.js (v14 or higher)
- PostgreSQL database (via Supabase or local)
- SMTP server for sending emails
- Google OAuth 2.0 credentials (for Google Sign-In)
-
Install dependencies:
npm install
-
Create a
.envfile based on.env.exampleand fill in your configuration:# Database Configuration DB_HOST=your-supabase-host DB_PORT=5432 DB_NAME=your-database-name DB_USER=your-database-user DB_PASSWORD=your-database-password # JWT Configuration JWT_SECRET=your-jwt-secret JWT_EXPIRES_IN=1h # Email Configuration SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your-email@gmail.com SMTP_PASS=your-app-specific-password # Server Configuration PORT=3000 NODE_ENV=development FRONTEND_URL=http://localhost:5500 USE_SSL=set-this-false-if-on-local-database-otherwise-true # Google OAuth Configuration GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret -
Create the database tables:
- Use the SQL commands in
src/utils/database.sql - Execute them in your Supabase SQL editor or local PostgreSQL
- Use the SQL commands in
-
Start the server:
# Development npm run dev # Production npm start
-
POST /api/auth/register- Register a new user{ "email": "user@example.com", "password": "password123" } -
POST /api/auth/google- Sign in with Google{ "credential": "google-id-token" } -
POST /api/auth/login- Login user{ "email": "user@example.com", "password": "password123" } -
POST /api/auth/forgot-password- Request password reset{ "email": "user@example.com" } -
POST /api/auth/reset-password- Reset password with token{ "token": "reset-token", "newPassword": "newpassword123" }and stat endpoint , user bio modification
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Google+ API
- Go to "Credentials" and create an OAuth 2.0 Client ID
- Add your authorized JavaScript origins:
http://localhost:5500 http://your-production-domain.com - Add your authorized redirect URIs:
http://localhost:5500/src/components/pages/login.html http://your-production-domain.com/src/components/pages/login.html - Copy your Client ID and Client Secret
- Update your
.envfile with these credentials
- Passwords are hashed using bcrypt
- JWT tokens for authentication
- Password reset tokens expire after 1 hour
- CORS enabled for frontend access
- SSL/TLS encryption for database connection