- Node.js (v18 or higher)
- MongoDB (v6 or higher) - Must be running locally or provide a connection string
- pnpm package manager
pnpm installThis will install all required packages including:
- Authentication:
bcryptjs,jsonwebtoken - Database:
mongodb,mongoose - Frontend dependencies
Create a .env file in the root directory:
cp .env.example .envEdit .env and set your values:
# Server Configuration
MONGODB_URI=mongodb://localhost:27017/blockverse
PORT=3000
JWT_SECRET=your-very-secure-random-secret-key-change-in-productionImportant: Change JWT_SECRET to a secure random string in production!
Make sure MongoDB is running on your system:
macOS (with Homebrew):
brew services start mongodb-communityLinux:
sudo systemctl start mongodWindows:
net start MongoDBOr use Docker:
docker run -d -p 27017:27017 --name mongodb mongo:6pnpm devThis starts:
- Vite development server (frontend)
- Express backend server with hot reload
- Both run concurrently
The application will be available at: http://localhost:3000
- Navigate to http://localhost:3000
- Click the "Register" tab
- Enter:
- Email: test@example.com
- Password: test123 (minimum 6 characters)
- Confirm Password: test123
- Click "Register"
You should see:
- Success toast notification
- Redirect to character creation screen
The server console will show:
🔵 Registration attempt: { email: 'test@example.com' }
✅ User created successfully: test@example.com
✅ Token generated, sending response
- Problem: MongoDB is not running
- Solution: Start MongoDB using the commands above
- Problem: Server is not running or API call failing
- Solution:
- Check server console for errors
- Open browser DevTools (F12) → Network tab
- Click Register and check for network requests
- Look for error messages in Console tab
- Problem: You've already registered with this email
- Solution: Try a different email or use the Login tab
- Problem: Server error (check server logs)
- Solution:
- Check MongoDB is running
- Check
.envfile is configured - Check server console for error details
POST /api/auth/register- Register new userPOST /api/auth/login- Login existing user
POST /api/character- Create character for authenticated user
coblox/
├── client/ # Frontend (React + Vite)
│ └── src/
│ └── pages/
│ ├── Login.tsx # Login & Registration
│ ├── CharacterCreate.tsx # Character creation
│ └── Profile.tsx # User profile
├── server/ # Backend (Express + MongoDB)
│ ├── db/
│ │ ├── index.ts # MongoDB connection
│ │ └── models/User.ts # User schema
│ ├── middleware/
│ │ └── auth.ts # JWT authentication
│ ├── routes/
│ │ ├── auth.ts # Login/Register endpoints
│ │ └── character.ts # Character endpoints
│ ├── utils/
│ │ └── jwt.ts # JWT utilities
│ └── index.ts # Server entry point
└── .env # Environment variables (create this)
# Try connecting with mongo shell
mongosh mongodb://localhost:27017/blockverseOpen http://localhost:3000/api/auth/register in your browser.
You should see: {"error":"Email and password are required"}
The server logs all authentication attempts with emojis:
- 🔵 = Attempt started
- ✅ = Success
- ❌ = Error/validation failed
If you're having token issues:
- Open DevTools (F12)
- Application tab → Local Storage
- Delete the
tokenentry - Refresh and try again
- Check server console for detailed logs
- Check browser console (F12) for frontend errors
- Ensure MongoDB is running
- Verify
.envfile exists and is configured