This repository contains the official website for the Technical Council of IIT Gandhinagar, structured as a decoupled application:
- Frontend: A Next.js App Router application configured for static HTML export (
output: "export"). - Backend: A Next.js App Router server/API application that manages database operations, admin dashboards, and custom Google OAuth sessions.
graph TD
Client[Browser Client :3000] -->|1. Request Login| GoogleOAuth[Google OAuth Consent Screen]
GoogleOAuth -->|2. Redirect Code| Backend[Backend API :3001]
Backend -->|3. Verify & Issue JWT Cookie| Client
Client -->|4. Authenticated API Requests with Cookies| Backend
- Authentication: Custom backend-only Google OAuth2 with secure
HttpOnlyJWT session cookies (admin_session). - Decoupling: The static frontend makes client-side requests using standard
fetchwithcredentials: "include"to allow the browser to forward credentials. - Admin Verification: Authorization is based on a dynamic authorized admin email list fetched from storage, fallback emails, and domain filters (
@iitgn.ac.in).
To configure Google Sign-In for the administration panel, follow these steps:
- Go to the Google Cloud Console.
- Select your project (or create a new one).
- Open the API & Services dashboard and navigate to the OAuth consent screen tab:
- Choose External user type.
- Enter your App information (App name, support email, developer contact details).
- Under Scopes, add
openid,.../auth/userinfo.email, and.../auth/userinfo.profile. - Add test users (your email) if the app is in "Testing" publishing status.
- Go to the Credentials tab:
- Click Create Credentials -> OAuth client ID.
- Select Web application as the application type.
- Authorized JavaScript origins:
- Development:
http://localhost:3000,http://localhost:3001 - Production: Add your public frontend and backend domain URLs (e.g.,
https://tech.iitgn.ac.in).
- Development:
- Authorized redirect URIs:
- Development:
http://localhost:3001/api/auth/callback - Production:
https://api.yourdomain.com/api/auth/callback(Must match your backend production domain).
- Development:
- Click Create and copy your Client ID and Client Secret.
Create .env files in both the frontend and backend directories.
| Variable | Description | Development | Production |
|---|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Local/Neon connection | Production Neon Database connection |
GOOGLE_CLIENT_ID |
Google OAuth Client ID | xxx.apps.googleusercontent.com |
xxx.apps.googleusercontent.com |
GOOGLE_CLIENT_SECRET |
Google OAuth Client Secret | GOCSPX-xxxx |
GOCSPX-xxxx |
NEXTAUTH_SECRET |
32+ character random string for signing JWTs | tech-web-iitgn-dev-secret |
Generate a secure phrase (e.g. openssl rand -base64 32) |
FRONTEND_URL |
The URL where the frontend is served | http://localhost:3000 |
https://tech.iitgn.ac.in |
BACKEND_URL |
The URL where the backend is served | http://localhost:3001 |
https://api.yourdomain.com |
NEXT_PUBLIC_ALLOW_DEV_LOGIN |
Allows bypassing Google Login using a mock email | true |
false |
| Variable | Description | Development | Production |
|---|---|---|---|
NEXT_PUBLIC_API_URL |
The URL of the backend API server | http://localhost:3001 |
https://api.yourdomain.com |
The backend runs as a standard Next.js Node.js server.
- Ensure all environment variables are correctly configured in
backend/.env. - Build the server bundle:
cd backend npm run build - Start the production server:
(We recommend using a process manager like PM2 in production:
npm run start
pm2 start npm --name "tech-backend" -- run start).
The frontend is built as a static application, exporting standard HTML, CSS, and JS files.
- Configure
frontend/.envto point to the production backend API endpoint. - Build and export the static assets:
This will run
cd frontend npm run buildnext buildwhich automatically exports all pages to thefrontend/outdirectory. - Deploy the contents of the
frontend/outfolder to any static hosting provider (e.g. Vercel, Netlify, AWS S3, or NGINX).
Important
Cross-Site Cookie Handling (CORS & SameSite): In production, because the frontend and backend run on different subdomains/domains:
- Set the cookie settings in
backend/src/app/api/auth/callback/route.tstosecure: trueandsameSite: "none". - Ensure CORS is correctly configured on the backend to accept credentials (
Access-Control-Allow-Credentials: true) from your frontend domain.
cd backend
npm run devcd frontend
npm run devIf NODE_ENV is not production or NEXT_PUBLIC_ALLOW_DEV_LOGIN is set to "true", you can log in locally without Google OAuth:
- Go to
http://localhost:3000/admin/login. - Click Sign in with Google.
- A popup will ask you for a developer email. Enter any email (defaults to
dev-admin@iitgn.ac.in) and press enter to be authenticated automatically.