A Next.js application that helps users discover relevant subreddits and generate posts that match community guidelines.
- ✅ Reddit OAuth 2.0 authentication
- ✅ Subreddit discovery and saving
- ✅ AI-powered post generation with GPT
- ✅ Draft management
- ✅ Post tracking and history
- ✅ Billing integration with Flowglad
- Framework: Next.js 15 with App Router
- Database: Supabase (PostgreSQL)
- Authentication: Custom Reddit OAuth
- AI: OpenAI GPT API
- Billing: Flowglad
- Styling: Tailwind CSS + shadcn/ui
- Reddit App Registration: You need to create a Reddit app at https://www.reddit.com/prefs/apps
- Node.js: Version 18 or higher
- npm: For package management
- Supabase Account: For database
- OpenAI API Key: For post generation
- Flowglad Account: For billing integration
-
Fork or clone this repository to your GitHub account
-
Import to Vercel:
- Go to vercel.com
- Click "Import Project"
- Select your GitHub repository
- Vercel will automatically detect it's a Next.js project
-
Configure Environment Variables in Vercel dashboard:
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key REDDIT_CLIENT_ID=your_reddit_client_id REDDIT_CLIENT_SECRET=your_reddit_client_secret REDDIT_REDIRECT_URI=https://your-app.vercel.app/auth/callback SESSION_SECRET=generate_a_random_32_char_string OPENAI_API_KEY=your_openai_api_key FLOWGLAD_SECRET_KEY=your_flowglad_secret_key -
Deploy:
- Click "Deploy"
- Wait for the build to complete
- Your app will be live at
https://your-app.vercel.app
-
Update Reddit App:
- Go to your Reddit app settings
- Update the redirect URI to
https://your-app.vercel.app/auth/callback
-
Configure Supabase:
- Ensure your Supabase project URL is accessible
- Check that RLS policies are properly configured
-
Test the deployment:
- Visit your deployed URL
- Try logging in with Reddit
- Test all features
- Go to https://www.reddit.com/prefs/apps
- Click "Create App" or "Create Another App"
- Fill in the details:
- Name: Your app name (e.g., "ReddiPost")
- App type: Select "web app"
- Description: Brief description of your app
- About URL: Your app's homepage (optional)
- Redirect URI:
http://localhost:3000/auth/callback
- Click "Create app"
- Note down your Client ID (the string under your app name) and Client Secret
npm install --legacy-peer-depsNote: We use --legacy-peer-deps due to peer dependency conflicts with some packages.
Create a .env.local file in the project root:
# Supabase
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
# Reddit OAuth
REDDIT_CLIENT_ID=your_reddit_client_id
REDDIT_CLIENT_SECRET=your_reddit_client_secret
REDDIT_REDIRECT_URI=http://localhost:3000/auth/callback
# Session
SESSION_SECRET=your_session_secret_32_chars
# OpenAI
OPENAI_API_KEY=your_openai_api_key
# Flowglad
FLOWGLAD_SECRET_KEY=your_flowglad_secret_keyRun the following SQL in your Supabase SQL editor:
-- Create saved_subreddits table
CREATE TABLE saved_subreddits (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id TEXT NOT NULL,
subreddit_name TEXT NOT NULL,
subreddit_display_name TEXT NOT NULL,
subreddit_icon_url TEXT,
subreddit_description TEXT,
subscriber_count INTEGER,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE(user_id, subreddit_name)
);
-- Create posts table
CREATE TABLE posts (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id TEXT NOT NULL,
reddit_post_id TEXT,
reddit_post_url TEXT,
title TEXT NOT NULL,
body TEXT NOT NULL,
tldr TEXT,
subreddit_name TEXT NOT NULL,
subreddit_display_name TEXT NOT NULL,
tone TEXT,
status TEXT NOT NULL CHECK (status IN ('draft', 'published', 'scheduled')),
upvotes INTEGER DEFAULT 0,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
submitted_at TIMESTAMP WITH TIME ZONE,
scheduled_for TIMESTAMP WITH TIME ZONE
);
-- Enable RLS
ALTER TABLE saved_subreddits ENABLE ROW LEVEL SECURITY;
ALTER TABLE posts ENABLE ROW LEVEL SECURITY;
-- Create RLS policies
CREATE POLICY "Users can manage their own saved subreddits" ON saved_subreddits
FOR ALL USING (true);
CREATE POLICY "Users can manage their own posts" ON posts
FOR ALL USING (true);npm run devThe app will start on http://localhost:3000
/
├── app/ # Next.js App Router
│ ├── api/ # API routes
│ │ ├── auth/ # Reddit OAuth endpoints
│ │ ├── generate-post/ # GPT post generation
│ │ ├── posts/ # Post management
│ │ └── subreddits/ # Subreddit management
│ ├── dashboard/ # Main app pages
│ │ ├── create/ # Post creation
│ │ ├── discover/ # Subreddit discovery
│ │ ├── drafts/ # Draft management
│ │ └── settings/ # User settings & billing
│ └── layout.tsx # Root layout
├── components/ # React components
├── lib/ # Utility functions
│ ├── auth.ts # Reddit auth helpers
│ ├── reddit-api.ts # Reddit API client
│ ├── supabase.ts # Supabase client
│ ├── openai.ts # OpenAI integration
│ └── flowglad.ts # Billing integration
└── vercel.json # Vercel configuration
- Authorization Request: User clicks "Login with Reddit" → redirects to Reddit's authorization page
- User Authorization: User grants permissions to your app on Reddit
- Callback: Reddit redirects back to your app with an authorization code
- Token Exchange: Your app exchanges the authorization code for access and refresh tokens
- API Access: Your app can now make authenticated requests to Reddit's API
GET /auth/login- Generate Reddit authorization URLGET /auth/callback- Handle Reddit OAuth callbackGET /api/user- Get authenticated user's profile informationGET /api/user/posts- Get user's recent postsPOST /auth/logout- Clear stored tokensGET /health- Check authentication status
The current implementation uses these scopes:
identity- Access to user's identity informationread- Read access to user's posts and comments
You can add more scopes as needed:
submit- Submit posts and commentsedit- Edit posts and commentsmodposts- Moderate posts and commentsmodflair- Manage user flairmodlog- Access moderation logsmodwiki- Edit wiki pagesmodconfig- Manage subreddit settingsmodmail- Access modmailmodcontributors- Manage contributorsmodtraffic- View traffic statsmodusertalk- Manage user talk pagesmodselfmail- Send modmailmodselflog- Access self moderation logsmodselfconfig- Manage self subreddit settingsmodselfwiki- Edit self wiki pagesmodselfmail- Send self modmailmodselflog- Access self moderation logsmodselfconfig- Manage self subreddit settingsmodselfwiki- Edit self wiki pages
- Open your browser and go to
http://localhost:3000 - Click "Login with Reddit"
- Authorize your app on Reddit's website
- You'll be redirected back to your app
- Use the buttons to:
- Get your user information
- View your recent posts
- Logout
- Store tokens securely: Use a database or secure session storage instead of in-memory storage
- Use HTTPS: Always use HTTPS in production
- Validate state parameter: Implement proper state validation to prevent CSRF attacks
- Rate limiting: Implement rate limiting for API endpoints
- Error handling: Add comprehensive error handling
- Logging: Add proper logging for debugging and monitoring
-
"Invalid client" error
- Check that your
REDDIT_CLIENT_IDandREDDIT_CLIENT_SECRETare correct - Ensure your app is properly registered on Reddit
- Check that your
-
"Invalid redirect URI" error
- Verify that the redirect URI in your Reddit app settings matches
http://localhost:3000/auth/callback - Check that the
REDDIT_REDIRECT_URIin your.envfile matches
- Verify that the redirect URI in your Reddit app settings matches
-
"Access denied" error
- Make sure your Reddit app is set to "web app" type
- Check that you're using the correct client credentials
-
CORS errors
- The server includes CORS middleware, but ensure your frontend is making requests to the correct URL
To see detailed error messages, check the server console output. The application logs all API requests and responses for debugging purposes.
GET /api/v1/me- Get current user informationGET /user/me/submitted- Get user's submitted postsPOST /api/v1/access_token- Exchange authorization code for tokensPOST /api/v1/access_token(refresh) - Refresh access token
User Information Response:
{
"name": "username",
"id": "t2_abc123",
"created_utc": 1234567890,
"link_karma": 1000,
"comment_karma": 500,
"is_gold": false,
"is_mod": false
}Posts Response:
{
"data": {
"children": [
{
"data": {
"title": "Post Title",
"subreddit": "subreddit_name",
"score": 42,
"permalink": "/r/subreddit/comments/abc123/post_title/",
"created_utc": 1234567890
}
}
]
}
}Feel free to submit issues and enhancement requests!
MIT License - see LICENSE file for details.