This application now supports a college-specific authentication system with PRN verification, LinkedIn OAuth, and admin approval workflow.
- Users can register with their college PRN (Permanent Registration Number)
- PRN format: 6-20 alphanumeric characters
- Requires admin approval if PRN or college information is provided
- Users can sign up/login using LinkedIn
- Automatically fetches college information from LinkedIn education data
- Requires admin approval if college info is found
- Basic Information: Name, Email, Password
- Username: Unique identifier for profile sharing and searching (optional)
- College Details:
- PRN Number
- Batch (e.g., 2021-2025)
- Department
- Year of Study (1-4)
- College (searchable dropdown)
- Students with PRN or college information require admin approval
- Admin dashboard to view pending requests
- Approve/Reject functionality
- Pending users can login but have limited access until approved
- Install Dependencies
cd backend
npm install- Environment Variables
Create a
.envfile with the following variables:
# LinkedIn OAuth
LINKEDIN_CLIENT_ID=your-linkedin-client-id
LINKEDIN_CLIENT_SECRET=your-linkedin-client-secret
LINKEDIN_CALLBACK_URL=http://localhost:5000/api/auth/linkedin/callback
# Session
SESSION_SECRET=your-session-secret-key
# Frontend URL
FRONTEND_URL=http://localhost:3000
# Database (ensure PostgreSQL is running)
DB_HOST=localhost
DB_PORT=5432
DB_NAME=collegecodehub
DB_USER=postgres
DB_PASSWORD=password
# JWT
JWT_SECRET=your-jwt-secret
JWT_EXPIRES_IN=7d-
LinkedIn OAuth Setup
- Go to LinkedIn Developers
- Create a new app
- Add OAuth 2.0 redirect URL:
http://localhost:5000/api/auth/linkedin/callback - Get Client ID and Client Secret
- Update
.envfile
-
Database Setup
- The application will automatically create tables on startup
- Tables created:
colleges,users(with new fields),problems,submissions, etc.
- Install Dependencies
cd frontend
npm install- Environment Variables
Create a
.env.localfile:
NEXT_PUBLIC_API_URL=http://localhost:5000POST /api/auth/register- Register with email/password + optional college infoPOST /api/auth/login- Login with email/passwordGET /api/auth/linkedin- Initiate LinkedIn OAuth flowGET /api/auth/linkedin/callback- LinkedIn OAuth callbackGET /api/auth/colleges- Search colleges
GET /api/auth/profile- Get user profilePUT /api/auth/profile- Update own profile
GET /api/auth/approvals/pending- Get pending approval requestsPUT /api/auth/approvals/:id- Approve/reject userGET /api/auth/users- List all usersPUT /api/auth/users/:id- Update any user
DELETE /api/auth/users/:id- Delete user
-
User fills registration form with:
- Name, Email, Password
- Username (optional)
- PRN Number
- College details (batch, department, year, college)
-
Backend validates:
- Email uniqueness
- Username uniqueness
- PRN format and uniqueness
-
User account created with
approval_status: 'pending' -
User redirected to pending approval page
-
Admin reviews and approves/rejects
-
User can login after approval
-
User clicks "Continue with LinkedIn"
-
LinkedIn authentication
-
Backend fetches education data from LinkedIn profile
-
If college found:
- Creates/finds college record
- Sets
approval_status: 'pending' - User needs admin approval
-
If no college info:
- Sets
approval_status: 'pending' - User needs admin approval
- Sets
-
User redirected to pending approval page
Access: /admin/approvals
Requirements: User must have role admin or super-admin
Features:
- View all pending registration requests
- See user details:
- Name, Email, Username
- PRN, College, Department, Batch, Year
- LinkedIn connection status
- Registration date
- Approve/Reject buttons
- Real-time updates
CREATE TABLE colleges (
id UUID PRIMARY KEY,
name VARCHAR(255) UNIQUE NOT NULL,
domain VARCHAR(255),
city VARCHAR(100),
state VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);New fields added:
username VARCHAR(50) UNIQUEprn VARCHAR(50) UNIQUEbatch VARCHAR(20)department VARCHAR(100)college_id UUID REFERENCES colleges(id)year_of_study INTEGERbio TEXTavatar_url TEXTverified BOOLEAN DEFAULT falselinkedin_id VARCHAR(255) UNIQUEapproval_status VARCHAR(20)- ('pending', 'approved', 'rejected')password_hash VARCHAR(255)- Now optional (for OAuth users)
The system validates PRN format:
- Length: 6-20 characters
- Format: Alphanumeric only
- Case insensitive (stored as uppercase)
- Unique across all users
Examples of valid PRNs:
ABC12345621BCE12342021001234
- Password Hashing: bcrypt with 12 salt rounds
- JWT Authentication: Tokens expire in 7 days
- Session Management: For OAuth flows
- Rate Limiting: 100 requests per 15 minutes per IP
- CORS Protection: Configured for frontend URL
- Input Validation: express-validator for all inputs
- SQL Injection Protection: Parameterized queries
To test admin features, manually update a user's role in the database:
UPDATE users
SET role = 'admin', approval_status = 'approved', verified = true
WHERE email = 'admin@example.com';- Go to
/auth/register - Fill in all fields including PRN
- Submit
- Should see pending approval message
- Login as admin
- Go to
/admin/approvals - Approve the request
- Login as the new user
- Configure LinkedIn OAuth credentials
- Go to
/auth/register - Click "Continue with LinkedIn"
- Complete LinkedIn authorization
- Should redirect to pending approval or home based on college info
- Check LinkedIn app credentials
- Verify redirect URL matches exactly
- Ensure
SESSION_SECRETis set - Check LinkedIn app has required permissions:
r_emailaddress,r_liteprofile
- Check PRN format (6-20 alphanumeric)
- Ensure no special characters
- Verify PRN is not already registered
- Verify user role is
adminorsuper-admin - Check JWT token is valid
- Ensure backend is running
- Verify PostgreSQL is running
- Check
.envdatabase credentials - Ensure database exists
- Email notifications for approval/rejection
- Bulk approval feature
- College verification system
- Student verification via email domain
- Profile completion percentage
- Alumni verification
- Department-specific features