feat: add Slack OAuth admin authentication - #46
Open
DJCrossman wants to merge 1 commit into
Open
Conversation
Adds next-auth v5 (pinned beta) with the Slack OIDC provider. Only administrators of the HackRegina Slack workspace can sign in: the signIn callback verifies the workspace team id and checks is_admin/is_owner via users.info (requires the bot token to have users:read). Sessions are stateless JWTs (12h), so no database is needed. - proxy.ts protects /admin/* and /api/admin/*: pages redirect to /admin/login, APIs get 401 JSON - requireAdmin()/requireAdminOrRedirect() in lib/adminAuth.ts give admin routes and layouts a second, defense-in-depth check - /admin/login renders a Sign in with Slack button and the AccessDenied message for non-admins - /admin is a placeholder shell replaced by the events list in a follow-up PR - Slack requires HTTPS redirect URLs, so local dev uses bun run dev:https Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack 1/4 — foundation for the Eventbrite admin dashboard. Next: Eventbrite data layer → events list UI → event detail with show-up predictions.
Summary
next-auth@5.0.0-beta.32(pinned exactly; peer-supports Next 16). JWT sessions (12h), no database.signIncallback verifies the id_token'shttps://slack.com/team_idclaim againstSLACK_TEAM_ID, then callsusers.infowith the bot token and only allowsis_admin || is_owner || is_primary_owner. Fails closed on any error.proxy.ts(Next 16's middleware convention) guards/admin/:path*and/api/admin/:path*— pages redirect to/admin/login?callbackUrl=…, APIs get 401 JSON.requireAdmin()/requireAdminOrRedirect()inlib/adminAuth.tsprovide a second, defense-in-depth check used by the admin layout (and by admin API routes in the next PR)./admin/login: server-action "Sign in with Slack" button; shows the access-denied message for signed-in non-admins; sanitizescallbackUrl(must start with/)./admin: placeholder shell (replaced by the events list in PR 3/4).Configuration (already done on the Slack app "HackRegina" A04G3FDT4TU)
https://hackregina.com/api/auth/callback/slack,https://localhost:3000/api/auth/callback/slackusers:readadded + reinstallAUTH_SECRET,AUTH_SLACK_ID,AUTH_SLACK_SECRET,SLACK_TEAM_ID(+AUTH_URL=https://localhost:3000for local HTTPS dev only)Note: Vercel preview deployments cannot complete Slack OAuth (redirect URLs must be pre-registered), so sign-in is testable locally (
bun run dev:https) and on production.Test plan
bun run lint/bun run buildpass/admin→ 307/admin/login?callbackUrl=%2Fadmin;/api/admin/*→ 401{"error":"Unauthorized"};/,/events,/techmapunaffected/admin; sign-out returns to login; non-admin gets the AccessDenied message🤖 Generated with Claude Code