A weighted spin-the-wheel for Visibuild's coffee club: it picks who chooses the café, posts the result to Slack, and lets admins manage people and weights. Sign-in is restricted to @visibuild.com Google accounts.
Stack: Next.js, Auth.js, Drizzle + Postgres (Neon in production, PGlite locally), Slack Web API.
Requires Node 24 (nvm use reads .nvmrc).
npm install
cp .env.example .env.local # skip if you already have one
npm run dev # http://localhost:3000
npm testIn .env.local:
DATABASE_URL=pglite:./.pgliteruns an embedded database that migrates itself.AUTH_DEV_LOGIN=1enables an email-only dev login (any@visibuild.comaddress). It is disabled wheneverNODE_ENV=production.- Set
AUTH_SECRET(npx auth secret) to a different value from production. The dev login mints sessions for any@visibuild.comemail, so a shared secret would let a local session be replayed against production.
- In the Google Cloud console, open Google Auth Platform.
- Branding: fill in the app name and support email.
- Audience: choose Internal.
- Clients → Create client → Web application:
- Authorized JavaScript origins:
http://localhost:3000andhttps://<app>.vercel.app - Authorized redirect URIs:
http://localhost:3000/api/auth/callback/googleandhttps://<app>.vercel.app/api/auth/callback/google
- Authorized JavaScript origins:
- Leave scopes at the defaults (
openid,email,profile). - Copy the client ID and secret into
AUTH_GOOGLE_IDandAUTH_GOOGLE_SECRET.
-
api.slack.com/apps → Create New App → From a manifest, pick the workspace, and paste:
display_information: name: Coffee Wheel description: Spins the wheel to pick who chooses coffee club features: bot_user: display_name: Coffee Wheel always_online: false oauth_config: scopes: bot: - emoji:read - chat:write - files:write - users:read - users:read.email settings: org_deploy_enabled: false socket_mode_enabled: false token_rotation_enabled: false
-
Install to Workspace (this may need workspace admin approval).
-
Copy the Bot User OAuth Token (
xoxb-…) intoSLACK_BOT_TOKEN. -
In the coffee club channel run
/invite @Coffee Wheel(private channels work too). -
Open the channel's details and copy the Channel ID (
C…) intoSLACK_CHANNEL_ID.
-
Create a free project at neon.tech.
-
Copy the pooled connection string into
DATABASE_URL. -
Run the migrations against it.
drizzle-kitdoes not load.env.local, so passDATABASE_URLexplicitly:DATABASE_URL='postgres://USER:PASSWORD@HOST/DBNAME?sslmode=require' npm run db:migrate
The seed migration makes dave@visibuild.com the first admin; he can add other admins in the app.
-
Import the repo into Vercel and set the project's Node.js version to 24.x (Settings → General).
-
Add environment variables:
Variable Value AUTH_SECREToutput of npx auth secret(unique to production)AUTH_GOOGLE_ID/AUTH_GOOGLE_SECRETfrom Google DATABASE_URLNeon pooled connection string SLACK_BOT_TOKEN/SLACK_CHANNEL_IDfrom Slack CRON_SECRETany long random string Do not set
AUTH_DEV_LOGINin Vercel. -
Deploy.
The cron in vercel.json refreshes the Slack custom emoji list daily. Trigger the first refresh manually:
curl -H "Authorization: Bearer $CRON_SECRET" https://<app>/api/cron/slack-emojiAfter adding a domain in Vercel, add its origin (https://coffee.example.com) to the Google client's JavaScript origins and https://coffee.example.com/api/auth/callback/google to its redirect URIs.
Vercel's Hobby plan is intended for non-commercial use; check its terms or use a paid plan for a company deployment. Nothing else is Vercel-specific: apart from the daily cron in vercel.json, it runs anywhere that hosts Next.js (schedule a call to the cron route elsewhere).