Skip to content

Commit 8427a93

Browse files
feat: Add GitHub OAuth verification tooling and fix production build errors
## Build Fixes - Fixed API type errors in assignments endpoint (requirements → instructions, totalPoints → maxPoints) - Fixed API type errors in lessons endpoint (removed non-existent description field) - Fixed test file type errors (proper React.ReactNode types, removed invalid mock fields) - Removed unused Enrollment type from dashboard ## GitHub OAuth Verification - Added verification script to check OAuth configuration - Created comprehensive setup guide (GITHUB_OAUTH_SETUP.md) - Added npm scripts: verify:oauth and verify:oauth:prod - Helps catch configuration issues before deployment ## Production Ready - All TypeScript errors resolved - Build passes successfully (276 static pages generated) - Test files updated to match current types - Ready for production deployment with GitHub authentication
1 parent 5993a07 commit 8427a93

File tree

10 files changed

+529
-34
lines changed

10 files changed

+529
-34
lines changed

GITHUB_OAUTH_SETUP.md

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
# GitHub OAuth Setup Guide for Production
2+
3+
This guide will help you set up GitHub OAuth authentication for your production deployment.
4+
5+
## Quick Verification
6+
7+
Run this command to verify your configuration:
8+
9+
```bash
10+
node scripts/verify-github-oauth.js
11+
```
12+
13+
For production environment check:
14+
15+
```bash
16+
node scripts/verify-github-oauth.js production
17+
```
18+
19+
---
20+
21+
## Step-by-Step Setup
22+
23+
### 1. Create GitHub OAuth App
24+
25+
#### For Production:
26+
27+
1. Go to https://github.com/settings/developers
28+
2. Click **"New OAuth App"**
29+
3. Fill in:
30+
```
31+
Application name: VetsWhoCode LMS Production
32+
Homepage URL: https://vetswhocode.vercel.app
33+
Authorization callback URL: https://vetswhocode.vercel.app/api/auth/callback/github
34+
```
35+
4. Click **"Register application"**
36+
5. Copy the **Client ID**
37+
6. Generate and copy the **Client Secret** (save immediately - you can't view it again!)
38+
39+
#### For Development (if you haven't already):
40+
41+
1. Go to https://github.com/settings/developers
42+
2. Click **"New OAuth App"**
43+
3. Fill in:
44+
```
45+
Application name: VetsWhoCode LMS Development
46+
Homepage URL: http://localhost:3000
47+
Authorization callback URL: http://localhost:3000/api/auth/callback/github
48+
```
49+
4. Click **"Register application"**
50+
5. Copy the **Client ID** and **Client Secret**
51+
52+
---
53+
54+
### 2. Environment Variables
55+
56+
#### Local Development (.env.local)
57+
58+
```bash
59+
# GitHub OAuth
60+
GITHUB_CLIENT_ID=your_development_client_id
61+
GITHUB_CLIENT_SECRET=your_development_client_secret
62+
63+
# NextAuth
64+
NEXTAUTH_SECRET=your_random_secret
65+
NEXTAUTH_URL=http://localhost:3000
66+
67+
# Organization (optional - allows org members to sign in)
68+
GITHUB_ORG=Vets-Who-Code
69+
```
70+
71+
#### Production (Vercel Environment Variables)
72+
73+
Add these in Vercel Project Settings → Environment Variables:
74+
75+
```bash
76+
# GitHub OAuth (from production OAuth app)
77+
GITHUB_CLIENT_ID=your_production_client_id
78+
GITHUB_CLIENT_SECRET=your_production_client_secret
79+
80+
# NextAuth
81+
NEXTAUTH_SECRET=your_production_secret
82+
NEXTAUTH_URL=https://vetswhocode.vercel.app
83+
84+
# Organization
85+
GITHUB_ORG=Vets-Who-Code
86+
```
87+
88+
**Generate NEXTAUTH_SECRET:**
89+
```bash
90+
openssl rand -base64 32
91+
```
92+
93+
---
94+
95+
### 3. Who Can Sign In?
96+
97+
Based on `src/pages/api/auth/options.ts`, the authentication logic is:
98+
99+
#### Development Mode:
100+
-**Anyone** with a GitHub account can sign in
101+
102+
#### Production Mode:
103+
- ✅ User `jeromehardaway` (hardcoded admin)
104+
- ✅ Members of the `Vets-Who-Code` GitHub organization
105+
- ❌ Other GitHub users are blocked
106+
107+
---
108+
109+
### 4. Testing Authentication
110+
111+
#### Test Locally:
112+
113+
1. Make sure `.env.local` has the correct development OAuth credentials
114+
2. Run the verification script:
115+
```bash
116+
node scripts/verify-github-oauth.js
117+
```
118+
3. Start the dev server:
119+
```bash
120+
npm run dev
121+
```
122+
4. Navigate to http://localhost:3000/login
123+
5. Click "Sign in with GitHub"
124+
6. Authorize the app
125+
7. You should be redirected back and signed in
126+
127+
#### Test Production:
128+
129+
1. Deploy to Vercel with production environment variables
130+
2. Navigate to https://your-app.vercel.app/login
131+
3. Sign in with GitHub
132+
4. If you're `jeromehardaway` or a member of `Vets-Who-Code` org, you should be able to sign in
133+
5. Others will be blocked
134+
135+
---
136+
137+
### 5. Troubleshooting
138+
139+
#### "Redirect URI Mismatch" Error
140+
141+
**Problem:** The callback URL doesn't match what's configured in GitHub OAuth app.
142+
143+
**Solution:**
144+
- Check your GitHub OAuth app settings at https://github.com/settings/developers
145+
- Ensure the callback URL exactly matches: `https://your-domain.com/api/auth/callback/github`
146+
- No trailing slashes!
147+
- HTTPS for production, HTTP for localhost
148+
149+
#### "Access Denied" in Production
150+
151+
**Problem:** User is not authorized to sign in.
152+
153+
**Solution:**
154+
- Verify the user is a member of the `Vets-Who-Code` GitHub organization
155+
- Check organization membership:
156+
```bash
157+
# As organization owner/admin, check:
158+
# https://github.com/orgs/Vets-Who-Code/people
159+
```
160+
- Or user must be `jeromehardaway`
161+
162+
#### Environment Variables Not Working
163+
164+
**Problem:** Environment variables seem to not be loaded.
165+
166+
**Solution:**
167+
- For Vercel: Check Project Settings → Environment Variables
168+
- Make sure you selected the correct environment (Production, Preview, Development)
169+
- Redeploy after adding environment variables
170+
- For local: Make sure `.env.local` exists and has correct format
171+
172+
#### "Failed to fetch" or Timeout Errors
173+
174+
**Problem:** GitHub API is not responding or rate limited.
175+
176+
**Solution:**
177+
- Check if GitHub is down: https://www.githubstatus.com/
178+
- The app has a 5-second timeout for GitHub API calls
179+
- Rate limiting: Make sure you're not making too many requests
180+
- Check your firewall/network isn't blocking GitHub API
181+
182+
---
183+
184+
### 6. Security Best Practices
185+
186+
1. **Never commit secrets to git**
187+
- Use `.env.local` for local development
188+
- Add `.env.local` to `.gitignore` (already done)
189+
- Use Vercel environment variables for production
190+
191+
2. **Use strong secrets**
192+
- Generate NEXTAUTH_SECRET with `openssl rand -base64 32`
193+
- Never use default values like "your-secret-key-here"
194+
195+
3. **Separate OAuth apps for dev/prod**
196+
- Create separate GitHub OAuth apps for development and production
197+
- Use different client IDs and secrets
198+
- This prevents dev testing from affecting production
199+
200+
4. **Organization access control**
201+
- Keep `GITHUB_ORG=Vets-Who-Code` to restrict production access
202+
- Regularly review organization members
203+
- Remove inactive users from the organization
204+
205+
5. **Monitor failed sign-in attempts**
206+
- Check Vercel logs for authentication errors
207+
- GitHub will send you emails about new authorizations
208+
209+
---
210+
211+
### 7. Verification Checklist
212+
213+
Use this checklist before deploying to production:
214+
215+
- [ ] Created production GitHub OAuth App
216+
- [ ] Callback URL matches exactly: `https://your-domain.com/api/auth/callback/github`
217+
- [ ] Added all required environment variables to Vercel
218+
- [ ] Generated strong NEXTAUTH_SECRET (32+ characters)
219+
- [ ] NEXTAUTH_URL points to production domain (not localhost)
220+
- [ ] GITHUB_ORG is set to `Vets-Who-Code`
221+
- [ ] Ran verification script: `node scripts/verify-github-oauth.js production`
222+
- [ ] Tested sign-in locally
223+
- [ ] Deployed to Vercel
224+
- [ ] Tested sign-in in production
225+
- [ ] Verified organization members can sign in
226+
- [ ] Verified non-members are blocked
227+
228+
---
229+
230+
### 8. Quick Reference
231+
232+
**GitHub OAuth App Settings:**
233+
- https://github.com/settings/developers
234+
235+
**Vercel Environment Variables:**
236+
- https://vercel.com/dashboard → Your Project → Settings → Environment Variables
237+
238+
**Check Organization Membership:**
239+
- https://github.com/orgs/Vets-Who-Code/people
240+
241+
**Verification Script:**
242+
```bash
243+
node scripts/verify-github-oauth.js [environment]
244+
```
245+
246+
---
247+
248+
## Need Help?
249+
250+
If you encounter issues:
251+
252+
1. Run the verification script and fix any errors
253+
2. Check the troubleshooting section above
254+
3. Review Vercel deployment logs
255+
4. Check GitHub OAuth app settings
256+
5. Verify environment variables are set correctly in Vercel

__tests__/pages/media.tests.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render, screen, fireEvent } from "@testing-library/react";
22
import { IMedia } from "@utils/types"; // Adjust path if needed
3-
import MediaPage from "../../pages/media.tsx"; // Adjust if path is different, e.g., src/pages/media
3+
import MediaPage from "../../src/pages/media"; // Adjust if path is different, e.g., src/pages/media
44

55
// Mock dependencies
66
jest.mock("@components/seo/page-seo", () => ({

__tests__/pages/projects.tests.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jest.mock("@components/seo/page-seo", () => ({
2020

2121
jest.mock("@layout/layout-01", () => ({
2222
__esModule: true,
23-
default: ({ children }) => <div data-testid="layout">{children}</div>,
23+
default: ({ children }: { children: React.ReactNode }) => <div data-testid="layout">{children}</div>,
2424
}));
2525

2626
jest.mock("@components/breadcrumb", () => ({
@@ -29,19 +29,19 @@ jest.mock("@components/breadcrumb", () => ({
2929
}));
3030

3131
jest.mock("@components/vwc-grid", () => ({
32-
VWCGrid: ({ children }) => <div data-testid="vwc-grid">{children}</div>,
32+
VWCGrid: ({ children }: { children: React.ReactNode }) => <div data-testid="vwc-grid">{children}</div>,
3333
}));
3434

3535
jest.mock("@components/markdown-renderer", () => ({
3636
__esModule: true,
37-
default: ({ content }) => <div data-testid="markdown">{content}</div>,
37+
default: ({ content }: { content: string }) => <div data-testid="markdown">{content}</div>,
3838
}));
3939

4040
// Mock the AnimatePresence component
4141
jest.mock("motion/react", () => ({
42-
AnimatePresence: ({ children }) => <div>{children}</div>,
42+
AnimatePresence: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
4343
motion: {
44-
div: ({ children }) => <div>{children}</div>,
44+
div: ({ children }: { children?: React.ReactNode }) => <div>{children}</div>,
4545
},
4646
}));
4747

@@ -56,10 +56,6 @@ const mockContributor: VWCContributor = {
5656
avatar_url: "https://example.com/avatar.jpg",
5757
html_url: "https://github.com/testuser",
5858
contributions: 10,
59-
id: 1,
60-
node_id: "node1",
61-
type: "User",
62-
url: "https://api.github.com/users/testuser",
6359
};
6460

6561
const mockRepo: VWCProjectRepo = {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"lint:fix": "yarn typecheck & yarn format & yarn lint --fix",
1818
"prepare": "husky install",
1919
"postbuild": "next-sitemap",
20-
"test": "jest"
20+
"test": "jest",
21+
"verify:oauth": "node scripts/verify-github-oauth.js",
22+
"verify:oauth:prod": "node scripts/verify-github-oauth.js production"
2123
},
2224
"dependencies": {
2325
"@ai-sdk/azure": "^2.0.69",

public/fallback-ig51mFqkghFuP2RH4aGuS.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)