eny.space#
your data, your space, use it enywhere.
A full-stack TypeScript application using Next.js with Supabase Auth and Stripe subscriptions for access-controlled hosting services.
Features#
- Authentication - Email-based authentication with Supabase Auth
- Subscriptions - Stripe subscription checkout and management
- Dashboard - User dashboard showing subscription status
- Protected API - Server endpoints only accessible to subscribed users
- Webhook handling - Server-side webhook processing for subscription events
Tech Stack#
- Frontend: Next.js, React, TypeScript
- Backend: Next.js Server Actions and Route Handlers
- Auth: Supabase Auth
- Database: Supabase PostgreSQL
- Payments: Stripe Subscriptions
Getting Started#
Prerequisites#
- Node.js 18+ installed
- A Supabase account and project
- A Stripe account
Installation#
- Clone the repository and install dependencies:
npm install
# or
yarn install
# or
pnpm install
- Set up Supabase:
- Create a new Supabase project at supabase.com
- Run the migration file to create the subscriptions table:
- Go to your Supabase project dashboard
- Navigate to SQL Editor
- Copy and run the contents of
supabase/migrations/001_subscriptions.sql
- Set up environment variables:
Create a .env.local file in the root directory:
# Supabase
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
# Stripe
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=your_publishable_key
STRIPE_SECRET_KEY=your_secret_key
STRIPE_WEBHOOK_SECRET=your_webhook_secret
NEXT_PUBLIC_STRIPE_PRICE_ID=your_stripe_price_id
# App URL (for redirects)
NEXT_PUBLIC_APP_URL=http://localhost:3000
Get your Supabase keys from your project settings → API.
Get your Stripe keys from your Stripe dashboard.
Create a subscription product and price in Stripe, then use the price ID for NEXT_PUBLIC_STRIPE_PRICE_ID.
- Start the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
The application will be available at http://localhost:3000.
Webhook Setup#
Local Development#
- Install the Stripe CLI and link your account:
stripe login
- Start webhook forwarding to your local server:
stripe listen --forward-to localhost:3000/api/webhooks
- Copy the webhook signing secret from the CLI output and add it to your
.env.localfile asSTRIPE_WEBHOOK_SECRET.
Production#
-
Deploy your application and copy the webhook URL (e.g.,
https://your-domain.com/api/webhooks). -
In your Stripe dashboard, go to Developers → Webhooks and add an endpoint:
- URL:
https://your-domain.com/api/webhooks - Events to listen to:
checkout.session.completedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedinvoice.payment_succeededinvoice.payment_failed
- URL:
-
Copy the webhook signing secret and add it to your production environment variables as
STRIPE_WEBHOOK_SECRET.
Testing#
Use test cards for testing payments. Common test cards:
4242 4242 4242 4242- Successful payment4000 0027 6000 3184- 3D Secure authentication required
Deployment#
This application can be deployed to any platform that supports Next.js, such as Vercel, Netlify, or your own infrastructure.
Make sure to set all required environment variables in your deployment platform.
Project Structure#
app/- Next.js app directory with pages and componentsdashboard/- User dashboard with subscription status and protected actionslogin/- Login pagesignup/- Sign up pageactions/- Server actions for auth and subscriptionsapi/- API routes (webhooks, protected server endpoints)
lib/- Client configurations (Stripe, Supabase)supabase/migrations/- Database migrationscomponents/- React componentsutils/- Utility functions
How It Works#
- Authentication: Users sign up/login with email via Supabase Auth
- Subscription: Users can subscribe via Stripe Checkout
- Webhook Sync: Stripe webhooks update subscription status in Supabase database
- Access Control: Dashboard shows subscription status and protected API buttons
- Protected Routes:
/api/server/[endpoint]routes check for active subscription before allowing access
Multi-Remote Git Setup#
This repo syncs to two servers (tangled.sh primary, GitHub mirror) using a custom all remote. Running git push all updates both simultaneously.
Current Config#
all git@tangled.sh:samsour.de/eny-space (fetch)
all git@github.com:Krekeny/eny-space.git (push)
all git@tangled.sh:samsour.de/eny-space (push)
origin git@tangled.sh:samsour.de/eny-space (fetch)
origin git@tangled.sh:samsour.de/eny-space (push)
Note: I previously had all with git@tangled.sh:samsour.de/eny-space as fetch only, so pushes were only going to GitHub and the tangled.sh repo wasn’t in sync. The config above fixes that by adding tangled.sh as a push URL on all.
Setup (New Clones)#
# Clone primary
git clone git@tangled.sh:samsour.de/eny-space
# Add GitHub mirror + tangled push
cd eny-space
git remote rename origin tangled
git remote add all git@tangled.sh:samsour.de/eny-space
git remote set-url --add --push all git@github.com:Krekeny/eny-space.git
git remote set-url --add --push all git@tangled.sh:samsour.de/eny-space
# Push everything
git push all --all
git push all --tags
How to Contribute#
- Clone:
git clone git@tangled.sh:samsour.de/eny-space - Branch:
git checkout -b your-feature - Work: edit →
git add . && git commit -m "Your message" - Push:
git push all(syncs both servers!) - Update:
git fetch --all && git checkout main && git pull tangled main
Pro tip: add an alias pushall="git push all" in your shell config (e.g. ~/.bashrc or ~/.zshrc) for speed.