I'll guide you through the complete setup process step-by-step.
First, make sure you have these installed on your system:
- Node.js (Download from nodejs.org)
- MySQL (Download MySQL Installer from mysql.com)
- Git (Download from git-scm.com)
# Install Homebrew first (if not installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Node.js and MySQL
brew install node
brew install mysql# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
# Install MySQL
sudo apt-get install mysql-serverOpen your terminal/command prompt and check:
node --version
npm --version
mysql --version
git --versionAll commands should show version numbers without errors.
# Create main project directory
mkdir gpg-demo
cd gpg-demo
# Create backend and frontend folders
mkdir server client
# Initialize backend
cd server
npm init -y
# Initialize frontend
cd ../client
npm init -ycd server
# Install production dependencies
npm install express cors dotenv cookie-parser jsonwebtoken google-auth-library @prisma/client
# Install development dependencies
npm install -D prisma
# Initialize Prisma
npx prisma initcd ../client
# Install React with Vite
npm install react react-dom
npm install -D @vitejs/plugin-react vite
# Create basic frontend structure
mkdir src
mkdir src/components# Login to MySQL (you'll be prompted for password)
mysql -u root -p
# Run these commands in MySQL prompt
CREATE DATABASE gpg_demo;
EXIT;PORT=4000
NODE_ENV=development
CLIENT_ORIGIN=http://localhost:5173
DATABASE_URL="mysql://root:your_mysql_password@localhost:3306/gpg_demo"
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production
GOOGLE_CLIENT_ID=your_google_oauth_client_id_here
VITE_GOOGLE_CLIENT_ID=your_google_oauth_client_id_here
VITE_API_BASE=http://localhost:4000/api
Now create all the files I mentioned in the previous response. Here's the quick way to create the directory structure:
# In server directory
cd server
mkdir -p src/lib src/services src/controllers src/routes src/middlewareCreate all the files with the content I provided:
server/prisma/schema.prismaserver/src/lib/prisma.jsserver/src/lib/jwt.jsserver/src/services/auth.service.jsserver/src/services/userData.service.jsserver/src/controllers/auth.controller.jsserver/src/controllers/userData.controller.jsserver/src/middleware/auth.middleware.jsserver/src/routes/auth.routes.jsserver/src/routes/userData.routes.jsserver/src/app.js
# In client directory
cd ../client
mkdir -p src/componentsCreate client files:
client/index.htmlclient/src/styles.cssclient/src/api.jsclient/src/GoogleLoginButton.jsxclient/src/Dashboard.jsxclient/src/App.jsxclient/src/main.jsxclient/vite.config.js
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable "Google+ API"
- Go to "Credentials" → "Create Credentials" → "OAuth client ID"
- Choose "Web application"
- Add authorized JavaScript origins:
http://localhost:5173 - Add authorized redirect URIs:
http://localhost:4000/api/auth/google - Copy the Client ID and update both
.envfiles
cd server
# Generate Prisma client
npx prisma generate
# Run migrations to create tables
npx prisma migrate dev --name init{
"name": "gpg-server",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "node src/app.js",
"prisma:generate": "prisma generate",
"prisma:migrate": "prisma migrate dev --name init"
},
"dependencies": {
"@prisma/client": "^5.18.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"google-auth-library": "^9.14.2",
"jsonwebtoken": "^9.0.2"
},
"devDependencies": {
"prisma": "^5.18.0"
}
}{
"name": "gpg-client",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview --port 5173"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@vitejs/plugin-react": "^4.3.1",
"vite": "^5.4.2"
}
}cd server
npm run devcd client
npm run dev- Open
http://localhost:5173in your browser - Click "Sign in with Google"
- Complete the Google login process
- You should see the dashboard with game features
- MySQL Connection Error: Make sure MySQL is running
- Port Already in Use: Change ports in
.envfiles - Google Login Error: Verify OAuth credentials and redirect URIs
- Module Not Found: Run
npm installin both directories
This setup will give you a complete Google Play Games-style demo with authentication, progress tracking, and a game-like interface!