feat: Add API token support via @better-auth/api-key#973
Conversation
- Add @better-auth/api-key dependency - Configure apiKey plugin with user-scoped keys and zb_ prefix - Add apiKeyClient to auth-client for frontend integration - Create API Tokens settings page with CRUD UI - Enable session mocking for API keys (enableSessionForAPIKeys) API keys support: - Create tokens via Settings > API Tokens - Authenticate via x-api-key header - 90-day default expiration - Enable/disable and revoke tokens
|
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
- Add apikey table schema for @better-auth/api-key plugin - Update requireAuth middleware to fallback to user's default org when activeOrganizationId is missing (API key mock sessions) - Pass full schema to drizzleAdapter for apikey model resolution
|
Hello @Rhonstin thanks for putting this together, unfortunately we already had two PRs lined up for this exact feature. I will close this one as the feature has already landed in main. Next time if you could discuss the implementation in the issue before jumping on implementation it will be easier to align |
Summary
@better-auth/api-keyplugin for programmatic API accessChanges
Backend
app/server/lib/auth.ts: AddedapiKey()plugin configurationzb_prefixenableSessionForAPIKeys: truefor automatic session creationFrontend
app/client/lib/auth-client.ts: AddedapiKeyClient()pluginapp/client/modules/settings/components/api-tokens-section.tsx: New UI componentapp/client/modules/settings/routes/settings.tsx: Added "API Tokens" tabUsage
Create Token
Authenticate
curl -H "x-api-key: zb_..." /api/v1/volumesFeatures
requireAuthmiddleware