basicAuth context?
Just tried out hono and wanted to add basic auth and wanted to pull data from the
Env
but the context is any
instead of what's set on the Bindings
. what am i doing wrong here?
2 Replies
To address the issue where the context
c
is of type any
instead of the expected type with Bindings
, you need to ensure that the context type is correctly inferred. This can be done by explicitly typing the context parameter in the verifyUser
function.
Explanation:
- Explicitly type the context parameter c
in the verifyUser
function as Hono.Context<{ Bindings: Env }>
to ensure that TypeScript correctly infers the type and provides autocompletion for c.env.PASS
.thanks for this @blurSkye π΅πΈπ. slight adjustment was to import
Context
from hono
as there wasn't a type Hono.Context
on my setup. maybe i was expecting some generics implementation of basicAuth
or verifyUser
of some sorts but this should do