Repurpose Engine is a Next.js App Router app that turns source content into LinkedIn, X, and Instagram drafts, then queues or schedules the selected draft through a user-connected Buffer account.
npm install
npm run devOpen http://localhost:3000.
Copy .env.example to .env.local and fill in your OpenAI, Firebase, and
Buffer OAuth values.
Firebase client auth:
NEXT_PUBLIC_FIREBASE_API_KEY=
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
NEXT_PUBLIC_FIREBASE_PROJECT_ID=
NEXT_PUBLIC_FIREBASE_APP_ID=Firebase Admin:
FIREBASE_PROJECT_ID=
FIREBASE_CLIENT_EMAIL=
FIREBASE_PRIVATE_KEY=Buffer:
BUFFER_CLIENT_ID=
BUFFER_CLIENT_SECRET=
BUFFER_REDIRECT_URI=http://localhost:3000/api/buffer/callback
BUFFER_AUTH_URL=https://auth.buffer.com/auth
BUFFER_TOKEN_URL=https://auth.buffer.com/token
BUFFER_API_BASE=https://api.buffer.comThe Firebase private key supports escaped newlines:
process.env.FIREBASE_PRIVATE_KEY?.replace(/\\n/g, "\n").
The app uses Firebase email/password auth on /login.
After sign-in or sign-up, the frontend gets a Firebase ID token and posts it to
/api/auth/session-login. The server verifies the ID token with Firebase Admin
and creates an httpOnly __session cookie. Server routes verify that cookie and
use the Firebase UID as the application user ID.
Logout calls /api/auth/session-logout, which clears the session cookie.
- In Buffer, create or open your developer/API app.
- Add the redirect URI that matches your environment:
http://localhost:3000/api/buffer/callbacklocally. - For production, add:
https://repurpose-engine-jet.vercel.app/api/buffer/callback. - Add the same URI to
BUFFER_REDIRECT_URI. - Add the Buffer client ID and secret to
BUFFER_CLIENT_IDandBUFFER_CLIENT_SECRET.
The app requests:
posts:write posts:read account:read offline_access
- The user signs in with Firebase.
- They click Connect Buffer.
/api/buffer/connectverifies the Firebase session cookie and redirects to Buffer with OAuth 2.0 Authorization Code + PKCE.- Buffer redirects back to
/api/buffer/callback. - The server verifies the Firebase session cookie, exchanges the code for
tokens, and stores them in Firestore at
bufferConnections/{firebaseUid}. /api/buffer/channelsrefreshes the token if needed and returns only channel/profile data to the frontend./api/publishverifies the Firebase session, validates that the selected Buffer channel belongs to that user, then publishes with that user's token.
Access tokens and refresh tokens are never exposed to the browser or stored in localStorage.
Buffer connections are stored in the bufferConnections collection with the
Firebase UID as the document ID:
bufferConnections/{uid}
Fields:
id
userId
provider
accessToken
refreshToken
expiresAt
scope
createdAt
updatedAt
Add all environment variables in Vercel Project Settings.
For FIREBASE_PRIVATE_KEY, paste the private key with escaped newlines, for
example:
-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n
Set production Buffer redirect URI to:
https://repurpose-engine-jet.vercel.app/api/buffer/callback
Add that exact URL in the Buffer Developer Dashboard.
npm run lint
npm run build