api key validation problem
When I search for api key using the DB, it appears, but doesn't work when I try the same using api key validate, I get an error Keys not found
I am using this in external api, which dont have auth setup thouhg, coz my main app is nextjs, and for hono I am using api keys so people can call endpoints
Solution:Jump to solution
you dont have the key hashing disabled, the keys table with the
key
column is a hashed version, it will not be the actual key, usally the key is provided to you when you create the key use the value instead.5 Replies
Please share your auth.ts and also where you are validating/creating api keys,
If you havn't disabled hashing for keys then the key you see in your database will actually be the Hashed API key and not the actual api key
aah probably that's the issue, thanks mate, lemme try
Solution
you dont have the key hashing disabled, the keys table with the
key
column is a hashed version, it will not be the actual key, usally the key is provided to you when you create the key use the value instead.You can disable hashing here @whizzy
https://www.better-auth.com/docs/plugins/api-key#api-key-plugin-options:~:text=disableKeyHashing%20boolean,users%27%20API%20keys.
-# ⚠️ Only do this in developement. In Production It's strongly recommended to not disable hashing. Storing API keys in plaintext makes them vulnerable to database breaches, potentially exposing all your users' API keys.
API Key | Better Auth
API Key plugin for Better Auth.
thanks mate