A WeTransfer-style file sharing service with authentication and tiered subscriptions using Polar and BetterAuth.
If you prefer, check out the full tutorial to learn how to build this application from scratch.
Authentication:
- Email/password signup and login
- Secure session management with BetterAuth
- Protected API endpoints
Free Tier:
- Upload files up to 100MB
- Files stored for 7 days
- Generate shareable download links
Premium Tier ($10/month):
- Upload files up to 5GB
- Files stored for 30 days
- Auth Service - User authentication with BetterAuth
- Files Service - File upload/download with object storage
- Payments Service - Polar subscription management and webhooks
- Frontend Service - Static HTML/JS frontend
Install Encore:
- macOS:
brew install encoredev/tap/encore - Linux:
curl -L https://encore.dev/install.sh | bash - Windows:
iwr https://encore.dev/install.ps1 | iex
Docker:
- Install Docker
- Start Docker
- Install dependencies:
npm install- Set required secrets:
# BetterAuth secret
encore secret set --dev BetterAuthSecret
# When prompted, enter a random string (e.g., output of: openssl rand -base64 32)
# Polar API token (get from https://sandbox.polar.sh/settings)
encore secret set --dev PolarAccessToken
# Paste your Polar sandbox access token- Start the backend (make sure Docker is running):
encore run- Open the frontend at
http://localhost:4000
Note: The example uses Polar's sandbox environment for testing without real payments.
- Open
http://localhost:4000 - Click "Don't have an account? Sign up"
- Enter your details and create an account
- You'll be automatically signed in
- Select a file under 100MB
- Click "Upload File"
- You'll see the download link and expiration date (7 days)
- Click "Upgrade Now" button
- You'll be redirected to Polar's sandbox checkout
- Complete the checkout (use test card info)
- Important: After checkout, webhooks won't work locally
Local limitation: Polar webhooks can't reach localhost, so your subscription won't activate automatically. See "Deployment" below for full webhook testing.
Open http://localhost:9400 to access Encore's local development dashboard with:
- API Explorer with interactive documentation
- Service architecture diagram
- Distributed tracing for all requests
- Database explorer
See the self-hosting instructions for how to use encore build docker to create a Docker image and configure it.
Deploy your application to a free staging environment in Encore's development cloud using git push encore:
git add -A .
git commit -m 'Commit message'
git push encoreSet your production secrets:
encore secret set --prod BetterAuthSecret
# For production Polar, also set:
# encore secret set --prod PolarAccessTokenYou can also open your app in the Cloud Dashboard to integrate with GitHub, or connect your AWS/GCP account, enabling Encore to automatically handle cloud deployments for you.
To enable automatic subscription activation:
- Go to https://sandbox.polar.sh/dashboard → Settings → Webhooks
- Add webhook URL:
https://[your-app].encr.app/webhooks/polar - Select events:
subscription.created,subscription.updated,customer.created
POST /auth/signup- Create new accountPOST /auth/signin- Sign inPOST /auth/signout- Sign out
POST /upload- Upload file (requires auth)GET /download/:fileId- Download file
GET /subscriptions/me- Check subscription status (requires auth)POST /checkout- Create Polar checkout session (requires auth)POST /webhooks/polar- Polar webhook handler
- Encore.ts - Backend framework with Infrastructure from Code
- BetterAuth - TypeScript authentication framework
- Polar - Merchant of record for subscriptions
- Drizzle ORM - Type-safe database queries
- PostgreSQL - Database (automatically provisioned by Encore)
- Object Storage - File storage (S3/GCS, automatically provisioned by Encore)
├── auth/ # Authentication service
│ ├── auth.ts # Signup/signin/signout endpoints
│ ├── handler.ts # Auth handler for protected endpoints
│ ├── better-auth.ts # BetterAuth configuration
│ └── migrations/ # Database schema for auth tables
├── files/ # File management service
│ ├── upload.ts # File upload endpoint
│ ├── download.ts # File download endpoint
│ └── bucket.ts # Object storage bucket
├── payments/ # Payments service
│ ├── checkout.ts # Create Polar checkout sessions
│ ├── webhooks.ts # Handle Polar webhooks
│ └── subscriptions.ts # Check subscription status
└── frontend/ # Static frontend
└── assets/
└── index.html # Single-page app
- Encore.ts Documentation
- BetterAuth Documentation
- Polar Documentation
- Tutorial Article - Full step-by-step guide
MIT