The app now uses the official Reddit OAuth API instead of unofficial JSON endpoints.
Authentication type: Application-Only OAuth (does not require user login)
- Suitable for displaying posts without user authentication
- Uses Client Credentials Grant Flow
src/services/redditAPI.js- Service for working with the official Reddit APInetlify/functions/reddit-token.js- Serverless function for secure token retrieval
src/features/Subreddit/subredditSlice.js- Updated to use the API servicesrc/features/Comments/commentsSlice.js- Updated to use the API servicesrc/features/SearchReddit/SearchReddit.js- Updated to use the API servicesrc/features/Comments/FullPostWithComments/FullPostWithComments.js- Simplified interface
.envand.env.example- Environment variables moved to Netlify
- Go to https://www.reddit.com/prefs/apps
- Click "are you a developer? create an app..."
- Choose "web app" type
- Fill in the required fields
- Get your Client ID and Client Secret
- Place
netlify/functions/reddit-token.jsin your project - In the Netlify dashboard, add environment variables:
REDDIT_CLIENT_ID=your_client_id REDDIT_CLIENT_SECRET=your_client_secret REDDIT_USER_AGENT=web:your-app-name:v1.0.0 (by /u/yourusername) - Mark them as "Secret" for security
- Deploy the project to Netlify
- Officially supported endpoints
- Stable response structure
- Less risk of sudden changes
- Authenticated requests have higher rate limits
- 100 requests per minute (compared to heavily limited anonymous access)
- Access to additional endpoints
- Better error handling
- Official documentation
- Follows Reddit Terms of Service
- Proper app identification via User-Agent
- API usage tracking
The official API has the following limits:
- 100 requests per minute for authenticated apps
- Limits are averaged over a 10-minute window to support burst traffic
- Monitor via response headers:
X-Ratelimit-Used: Requests usedX-Ratelimit-Remaining: Requests remainingX-Ratelimit-Reset: Time until reset
await redditAPI.getSubredditPosts('javascript', { limit: 25 })await redditAPI.getPostComments('javascript', 'abc123', { limit: 50 })await redditAPI.searchReddit('react hooks', {
limit: 25,
sort: 'relevance',
time: 'all'
})- Client Secret is stored only in Netlify environment variables
- Tokens are obtained via the serverless function
/.netlify/functions/reddit-token - Secrets are never exposed to client code
- HTTPS secures all requests
Browser → Netlify Function → Reddit API
↑
(secrets stored here)
- Required by Reddit API
- Must include app name and developer contact
- Format:
<platform>:<app ID>:<version string> (by /u/<reddit username>)
- Check your Client ID and Client Secret
- Make sure your app is registered as a "web app"
- Check the User-Agent format
- Reddit API is properly configured for CORS
- If issues occur, check endpoint URLs
- Monitor response headers for rate limit info
- Implement delays between requests if needed
- Token caching - Store tokens in localStorage
- Retry mechanism - Automatic retries on errors
- Pagination - Load next pages of posts
- Filtering - Additional search parameters
- User Authentication - User login for personalized features
- Track API rate limit usage
- Cache frequently requested data
- Optimize the number of requests
Migrating to the official Reddit API makes your app more reliable, performant, and compliant with platform rules. While authentication setup requires extra steps, the benefits far outweigh the complexity.