"'internal' authentication" for a HTTP client
Personally, almost all of my Convex functions are meant to be used backend-to-db (might be questionable design but let's forget that for a minute). In finding https://discord.com/channels/1019350475847499849/1103697990331416587 and realizing that, in theory, anyone can call my session & rate limiting functions, I first panicked, and then came with an acceptable solution.
ConvexHttpClientAsServer
for context
DB_TOKEN
on Convex matches CONVEX_DB_TOKEN
on server
usage
findBySid
method
this is kind of a madness but it works - no need to dotenv anywhere else, and it's still typesafe.
note: to validate the function's arguments - in case 'dbToken' doesn't exist, args will be never
So yeah, if anyone wants to use this, you may :HuTaoThumbsUp:2 Replies
Yup, validating a fixed token is the simplest kind of authentication, and it works as long as you never reveal the token. Nicely done!
Thank you!