Skip to content

Commit bed930f

Browse files
fix: use production URL in email links instead of localhost fallback (#9)
- Update request-access API route to use request origin when NEXTAUTH_URL is not set - Remove localhost fallback in access-requests-service.ts - Add proper error handling for missing NEXTAUTH_URL - Update documentation to clarify NEXTAUTH_URL must be set to production URL - Add missing environment variable documentation for email notifications Fixes #8 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Seth Webster <sethwebster@users.noreply.github.com>
1 parent 1791de1 commit bed930f

5 files changed

Lines changed: 22 additions & 7 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,19 @@ Copy `.env.example` to `.env` and provide:
135135
- `GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET` - OAuth App credentials
136136
- `GITHUB_TOKEN` - Personal access token with `read:user` and `public_repo` scopes
137137
- `NEXTAUTH_SECRET` - Generate with `openssl rand -base64 32`
138-
- `NEXTAUTH_URL` - http://localhost:3000
138+
- `NEXTAUTH_URL` - http://localhost:3000 (for development) or your production URL (e.g., https://yourdomain.com)
139139

140140
**OpenAI (optional - for AI image generation):**
141141
- `OPENAI_API_KEY` - OpenAI API key
142142

143+
**Email Notifications (required for access request emails):**
144+
- `RESEND_API_KEY` - Resend API key for sending emails
145+
- `RESEND_FROM_DOMAIN` - Domain for sending emails (e.g., yourdomain.com)
146+
- `ADMIN_EMAIL` - Email address to receive access request notifications
147+
148+
**Redis (required for access control):**
149+
- `REDIS_URL` - Redis connection URL (e.g., redis://localhost:6379)
150+
143151
## Key Features
144152

145153
### Unified Foundation + Store

README_STORE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Copy `.env.example` to `.env` and provide:
4949
- `GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET` - OAuth App credentials
5050
- `GITHUB_TOKEN` - Personal access token with `read:user` and `public_repo` scopes
5151
- `NEXTAUTH_SECRET` - Generate with `openssl rand -base64 32`
52-
- `NEXTAUTH_URL` - http://localhost:3000
52+
- `NEXTAUTH_URL` - http://localhost:3000 (for development) or your production URL (e.g., https://yourdomain.com)
5353

5454
**OpenAI (optional - for AI image generation):**
5555
- `OPENAI_API_KEY` - OpenAI API key

docs/store/STORE_MANAGEMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ GITHUB_CLIENT_ID=xxxxx
6565
GITHUB_CLIENT_SECRET=xxxxx
6666
GITHUB_TOKEN=ghp_xxxxx
6767
NEXTAUTH_SECRET=xxxxx
68-
NEXTAUTH_URL=http://localhost:3000
68+
NEXTAUTH_URL=http://localhost:3000 # Use production URL (e.g., https://yourdomain.com) when deployed
6969
```
7070

7171
### 2. API Tokens

src/app/api/request-access/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export async function POST(request: NextRequest) {
7575
const approveToken = AccessRequestsService.generateActionToken(accessRequest.id, 'approve');
7676
const denyToken = AccessRequestsService.generateActionToken(accessRequest.id, 'deny');
7777

78-
const baseUrl = process.env.NEXTAUTH_URL || 'http://localhost:3000';
78+
// Get base URL from request or environment variable
79+
const requestUrl = new URL(request.url);
80+
const baseUrl = process.env.NEXTAUTH_URL || `${requestUrl.protocol}//${requestUrl.host}`;
7981
const approveUrl = `${baseUrl}/api/admin/request-action?token=${approveToken}`;
8082
const denyUrl = `${baseUrl}/api/admin/request-action?token=${denyToken}`;
8183
const reviewUrl = `${baseUrl}/admin/requests?id=${accessRequest.id}`;

src/lib/admin/access-requests-service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ export class AccessRequestsService {
195195
}
196196

197197
const fromDomain = process.env.RESEND_FROM_DOMAIN || 'yourdomain.com';
198-
const baseUrl = process.env.NEXTAUTH_URL || 'http://localhost:3000';
198+
const baseUrl = process.env.NEXTAUTH_URL;
199+
200+
if (!baseUrl) {
201+
console.error('❌ NEXTAUTH_URL not configured - email will not include links');
202+
// Still send email, but without the link
203+
}
199204

200205
console.log(` From: noreply@${fromDomain}`);
201206
console.log(` To: ${email}`);
@@ -212,9 +217,9 @@ export class AccessRequestsService {
212217
<h1 style="color: #10b981; font-size: 32px;">🎉 Welcome!</h1>
213218
<p style="font-size: 18px; color: #fff;">Your access request has been approved.</p>
214219
<p style="color: #aaa; margin: 20px 0;">You can now sign in and access the React Foundation.</p>
215-
<a href="${baseUrl}" style="display: inline-block; margin-top: 20px; padding: 14px 32px; background: #06b6d4; color: #000; text-decoration: none; border-radius: 8px; font-weight: bold;">
220+
${baseUrl ? `<a href="${baseUrl}" style="display: inline-block; margin-top: 20px; padding: 14px 32px; background: #06b6d4; color: #000; text-decoration: none; border-radius: 8px; font-weight: bold;">
216221
Sign In Now
217-
</a>
222+
</a>` : '<p style="color: #666; margin-top: 20px;">Please visit the React Foundation to sign in.</p>'}
218223
</div>
219224
</body>
220225
</html>

0 commit comments

Comments
 (0)