Repository navigation
Conversation
Better Auth's api-key plugin needs a default config for create/get/update/delete calls without a configId, and ours only has user-keys and org-keys. Fill the configId in a before hook: user-keys for personal calls, org-keys for a create that names an organizationId. Existing keys, prefixes and explicit configId calls are unchanged. Closes NEARBuilders#883
This branch has not been deployed
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.
Closes #883
The api-key plugin only has the
user-keysandorg-keysconfigs, so any Better AuthapiKey.create/get/update/deletecall without aconfigIdthrew "No default api-key configuration found". That's what broke Settings → API Keys on feedback.nearbuilders.org.The plugin won't take a config without a
configIdwhen you pass more than one, and adding a third"default"config would make a new kind of key that session lookup (key.configId === "user-keys") and the verify fallback loop don't know about. So this keeps every personal key onuser-keysand fills theconfigIdin with a small before hook (apiKeyDefaultConfig) when a call leaves it out:create({ name })→user-keys(api_…)create({ name, organizationId })→org-keys(org_…)get/update/deletewithoutconfigId→user-keysconfigIdare untouched, so existing keys, prefixes and the explicituser-keys/org-keyscallers (nearbuilders.org, feedback v2-platform: 13 provider consolidation — one self-hostable alchemy program #287, the org pages) behave the same.list()without aconfigIdalready returned the caller's personal keys. Tested that existing and new keys both show up and org keys don't.One thing to note: a bare
delete/updateon an org key now gets "key not found" instead of the old "no default config" error. Org callers already passorg-keys.Tested
plugins/auth/tests/integration/api-keys.test.tshit/api/auth/api-key/*throughauth.handlerwith a session cookie, the same way a child app's client does: bare create (personal and org), list, get, update, delete. Without the hook the create, list, get and delete tests fail, and with it they pass.api-keys,session,auth-context,permissionsandcredential-less-clientintegration suites: 47/47 passing locally.pnpm run typecheckpasses. Biome is clean. oxlint wouldn't load its Effect plugin config locally, so CI covers it.No UI change.